for -- 自动循环 for (int x = 1;x <= 5;i++){System.out.println(x)}
while -自动循环 int = 1;while(x《=5){System.out.println(x);x++;}
Alt+回车 自动修复 Ctrl + alt +L 自动复位
public static void 方法(int arr) 无返回return 调用:方法(arr);
public static int 方法(int arr) {
int max =arr[]} 有返回return max; 调用:int 变量 = 方法(arr); sout 变量 或者 sout 方法(arr)
public class Student 举类名 测试类
private String name; private私有安全化 Student p =new Student(name,age);
private int age 如果有Scanner String name = sc.nextLine();
String age = sc.nextInt();
public Student(){} 创建无参对象 p.setName();
public Student(String name,int age){ p.setAge();
this.name=name;
this.age =age;} 创建有参对象 p.work();
public void setName(String name) {
this.name = name; } 无返回值 set sout(+ name ) 或者sout(+ p.getName)
public String getName() {
return name; 有返回值 get
public void setAge(int age) {
this.age = age;} 无返回值 set
public int getAge() {
return age; 有返回值 get
public void work() {
System.out.println("读读书吧");} 定义动作
pubilc String() 创建空白
String s =“abc” 内容abc StringBuilder sb = new StringBuilder();
sb.append("[");
String s = new String();
equals 比较 String s =sb.toString(); StringBuilder sb = new StringBuilder(s);
sout"sb"
自定义字符串反转
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String line = sc.nextLine();
String s = fan(line);
System.out.println(s);
}
public static String fan(String s) {
StringBuilder sb = new StringBuilder(s);
sb.reverse();
String ss = sb.toString();
return ss;
增加字符到集合 array.add(" ") 定义集合 ArrayList<Student> array = new ArrayList<>();
E remove(int index); 删除索引位置 array.remove(1) for (int i = 0; i <array.size() ; i++) {
E set(int index,E element); 修改指定索引 arr.set(1,2) Student number = array.get(i);
E get(int index); 直接返回索引 arr.get(1) System.out.println(number); 集合遍历
int size(); 返回元素个数 arr.size();
for (int i = 0; i < array.size(); i++) {
Teacher num = array.get(i);
System.out.println("姓名:" + num.getName() + "," + "年龄:" + num.getAge());