第9讲.面向对象之封装
第10讲.面向对象之封装.续
《Java核心技术卷一》p40~p50
测试
1.
import java.util.Scanner;
public class Zhouhai{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int number1=(int)(Math.random()*1000);
int number2=(int)(Math.random()*1000);
System.out.println(number1+"+"+number2+"=?");
int daan=input.nextInt();
if(daan==number1+number2)
System.out.println("你的答案是正确的!");
else
System.out.println("对不起!你错了!");
}
}
2.
import java.util.Scanner;
public class Zhouhai{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int[] number=new int[10];
System.out.println("输入10到1000的十个数:");
for(int i=0;i<10;i++)
number[i]=input.nextInt();
System.out.println("排序前:");
for(int i=0;i<10;i++)
System.out.print(number[i]+" ");
java.util.Arrays.sort(number);
System.out.println("\n排序后:");
for(int i=0;i<10;i++)
System.out.print(number[i]+" ");
}
}