本人为小新一枚,在学Java基础,每天练习一下,会将每日所学发上来
大家有更好的方法欢迎留言告诉我,感激不尽
package exam_class1;
import java.util.Random;
public class HelloWorld_10 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = new int[6];
int temp = 0;
Random r = new Random();
for (int i = 0; i < a.length; i++) { //给数组赋值
a[i] = r.nextInt(100);
System.out.println(a[i]);
}
System.out.println("数组反转后为:");
for (int j = 0; j < a.length; j++) {
for (int k = 0; k < j; k++) {
if ((j+k) == (a.length-1)) {
temp = a[j];
a[j] = a[k];
a[k] = temp;
}
}
}
for (int i = 0; i < a.length; i++) { //打印数组
System.out.println(a[i]);
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)