1、使用方法重载分别实现了两个和三个整数的相加 class A{ }
public class Exam1{
public static void main(String[] args){ A obj =new A();
System.out.println(obj.add(1,2)); System.out.println(obj.add(1,2,3)); } }
//2.编写程序使用冒泡法对一组数进行排序 public class Exam1 {
public static void main(String[] args){
int[] a = {31,42,21,50,12,60,81,74,101,93}; int temp;
for(int i=0;i<10;i++)
for(int j=0;ja[j+1]){ public int add(int a,int b) { }
public int add( int a, int b, int c ) { }
return a+b+c; return a+b;
temp = a[j]; a[j]=a[j+1];
a[j+1]=temp ; }
for(int i=0;i
//3.定义一个线程PrintThread,该线程打印输出1~1000之间所有3的倍数,每输出一个数休眠1500毫秒,在main方法中创建该线程的一个实例,并启动该线程。 class PrintThread extends Thread{ public PrintThread(String str) {
super(str) ; // 调用父类的构造方法 }
public void run() {
for(int i=1;i<=1000;i++) {
if(i % 3 ==0)
System.out.println(this.getName()+\
try {
PrintThread.sleep(1500); // 休眠1500毫秒 }
catch (Exception e) { System.out.println(e.toString()); } } }
public class Exam4{
public static void main(String[] args) }
//4. 编写程序通过静态方法调用从包含10个学号的数组中随机抽取一个学号并输出显示。 public class EEE {
public static String getXh(){
String[] xhs = {
PrintThread myThread = new PrintThread(\
myThread.start(); //启动线程 } }
{\01207\
int index = (int)(Math.random()*10);
//生成0~9之间的随机数。
return xhs[index];
}
public static void main(String[] args){
System.out.println(\随机抽取的学号为:\
EEE.getXh() ); }
//5.判断一个数是否是素数 import java.io.*; public class Exam2 { }
public static void main(String[] args) throws IOException {
BufferedReader
br
=
new
BufferedReader(new
InputStreamReader(System.in));
String input = br.readLine(); int flag=0;
int x = Integer.parseInt(input);
int y = (int)Math.sqrt(x);
for(int i=2;i<=y;i++){ if(x % i==0){
System.out.println(\不是素数\ flag=1; break;
}
}
} }
if( flag==0 )
System.out.println(\是素数\
6. “三天打鱼两天晒网”。某人从2010年1月1日起三天打鱼两天晒网,编程计算2010年5月1日,他在打鱼还是在晒网。打鱼则输出1,晒网则输出0。 public class Exam4 {
public static void main(String[] args) {
int[ ] dpm={0,31,28,31,30,31,30,31,31,30,31,30,31}; int month=5; // 表示5月 int day=1; // 表示1日 for(int i=0; i day = day % 5; if ( day >0 && day<=3 ) System.out.println(\ // 表示打鱼 else System.out.println(\ // 表示晒网 }