1.
package cn.test2.hp;
public class array {
public static void main(String[] args){
int a[]={1,6,4,12,98};
for(int i=0;i<a.length;i++){
System.out.print("a["+i+"]"+"="+a[i] +"\t");
}
}
}
2.
package cn.test2.hp;
public class array2 {
public static void main(String[] args) {
String name = "姓名";
String number = "学号";
String Javascore = "java基础成绩";
System.out.println("输出学生个人信息内容");
String array[][] = new String[][] {
{ name + ":张三", number + ":1209888", Javascore + ":77" },
{ name + ":赵帅", number + ":1206578", Javascore + ":89" },
{ name + ":王红", number + ":1209778", Javascore + ":96" } };
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j] + "\t");
}
System.out.println();
}
}
}
3.冒泡练习
package cn.test2.hp;
public class bubbling {
public static void main(String[] args) {
int a[]=new int[]{1,6,4,120,98,4};
int c=-1;
for(int i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[j]>a[i]){
c=a[i];
a[i]=a[j];
a[j]=c;
}
}
}
for(int j=0;j<a.length;j++){
System.out.print(a[j]+"\t");
}
}
}