java学习(2)
外置类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| public class StudentTest { public static void main(String[] args) { Student s=new Student("straw",20); System.out.println(s.getAge()); System.out.println(s.getName());
} } class Student{ private String name; private int age; public Student() { System.out.println(name); System.out.println(age); } public Student(String name,int age) { this.name=name; this.age=age; } public void setName(String name) { this.name=name; } public int getAge() { return age; } public String getName() { return name; } }
|
输出
字符串拼接
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public class Demo { public static void main(String[] args) { int[] arr={1,2,3}; String str=arrToString(arr); System.out.println(str); } public static String arrToString(int[] arr) { if(arr==null) { return ""; } if(arr.length==0) { return "[]"; } String result= "["; for (int i = 0; i < arr.length-1; i++) { result+=arr[i]+","; } result=result+arr[arr.length-1]+"]"; return result; } }
|
输出
-
Next Post
llvm IR常用指令一
-
Previous Post
java学习(1)