作业答案

2019-03-22 10:33

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(\ // 表示晒网 }


作业答案.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:四年级科学下册 变来变去的盐教案 湘教版

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: