1. Manual formatting
1. Open the program, select the code to be formatted 2. Click the menu
on the menu bar 3. Click the option on the drop-down menu 4. The code has been formatted Source code:Source
Format
package TestDemo;
import java.util.Scanner;
public class Cipher {
private static int[] enc_key = {
6, 3, 0, 4, 5, 1, 2 }; // 加密密钥
private static int[] dec_key = {
2, 5, 6, 1, 3, 4, 0 }; // 解密密钥
public static void main(String[] args) {
char[][] m = new char[2][7];
char[][] c = new char[2][7];
char[][] dec_m = new char[2][7];
System.out.println("请输入两行7个英文字符的明文:");
try (Scanner scanner = new Scanner(System.in)) {
m[0] = scanner.nextLine().toCharArray();
m[1] = scanner.nextLine().toCharArray();
for (int i = 0; i < 7; i++) {
c[0][enc_key[i]] = m[0][i];
c[1][enc_key[i]] = m[1][i];
}
for (int i = 0; i < 7; i++) {
dec_m[0][dec_key[i]] = c[0][i];
dec_m[1][dec_key[i]] = c[1][i];
}
System.out.println("您输入的原始明文为:");
System.out.println(m[0]);
System.out.println(m[1]);
System.out.println("加密结果为:");
System.out.println(c[0]);
System.out.println(c[1]);
System.out.println("解密结果为:");
System.out.println(dec_m[0]);
System.out.println(dec_m[1]);
} catch (Exception e) {
System.err.println(e);
}
}
}
2. Automatic formatting
1. In the menu bar, click Window
the menu
2, select in the drop-down bar Preferences
3, click Java
, select Editor
, and then click Save Actions
option
4, the default is not checked, just check it
5, simply test
the code:
package TestDemo;
public class Rotor {
public static void main(String args[])
{
String str="rotor",sub1;
int i=0,n;
boolean yes=true;
if (args.length>0)
str=args[0];
System.out.println("str="+str);
n=str.length();
char ch1,ch2;
String temp="";
for (i=0;i<n;i++) {
sub1=str.substring(i,i+1);
temp=sub1+temp; }
System.out.println("temp="+temp);
System.out.println(str+":"+str.equals(temp));
}
}
Ⅰ. The newly created class has not saved the code
Ⅱ. After the code is written, Ctrl+s
save it and the code will be automatically formatted