while(endTime-startTime<180000){ try{ if(s[count%s.length].equals(\绿灯\ System.out.println(\绿灯亮\ Thread.currentThread().sleep(30000); } if(s[count%s.length].equals(\红灯\ System.out.println(\红灯亮\ Thread.currentThread().sleep(10000); }
if(s[count%s.length].equals(\黄灯\
System.out.println(\黄灯亮\ Thread.currentThread().sleep(3000); } count++; endTime=System.currentTimeMillis(); }catch(Exception e){ e.printStackTrace(); } } } }
class TestMyThread3 { public static void main(String[] args){ String[] s={\绿灯\红灯\黄灯\ Thread t=new Thread(new MyThread3(s)); t.start(); } }
评分标准:
1、写出能完成题目要求功能的、可正常运行的java程序,给满分,否则0分 ~~~c
从键盘输入一串字符串,运行程序,将首字母变为大写,其它小写。编写程序,完成上述功能。 ~~~c
输出下列形式的方阵。 0 0 0 0 0 1 1 1 0 1 2 2 0 1 2 3
~
参考程序如下: public class Phalanx {
public static void main(String args[]) {
int n=4; //阶数 for (int i=0;i for (int j=0;j System.out.print(\ \ System.out.println(); } } } 评分标准: 1、写出能完成题目要求功能的、可正常运行的java程序,给满分,否则0分 ~~~b 输出下列形式的数字三角阵(当n=4时)。 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 ~ 参考程序如下: public class Tower { public static void main(String args[]) { int n=4; //行数 for (int i=1;i<=n;i++) { for (int j=1;j<=n-i;j++) //前导空格 System.out.print(\ \ for (int j=1;j<=i;j++) System.out.print(\ \ for (int j=i-1;j>0;j--) System.out.print(\ \ System.out.println(); } } } 评分标准: 1、写出能完成题目要求功能的、可正常运行的java程序,给满分,否则0分 ~~~b 输入三个整数,请把这三个数由小到大输出。 ~ 参考程序如下: import java.util.Scanner; public class 三整数由小到大输出 { public static void main(String[] args) { int i,j,x,k; Scanner sc = new Scanner(System.in); System.out.print(\请输入三个整数:\\n\); i=sc.nextInt(); j=sc.nextInt(); k=sc.nextInt(); if(i>j) {x=i; i=j; j=x;} if(i>k) {x=i; i=k; k=x;} if(j>k) {x=j; j=k; k=x;} } System.out.println(\三个整数由小到大输出为\+i+\+j+\ \+k); } 评分标准: 1、写出能完成题目要求功能的、可正常运行的java程序,给满分,否则0分 ~~~b 有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大? ~ 参考程序如下: public class 第五个人多大 { public static void main(String[] args) { int a,b,c,d,e; a=10; } b=a+2; c=b+2; d=c+2; e=d+2; System.out.println(\第五个人年龄为:\+e); } 评分标准: 1、写出能完成题目要求功能的、可正常运行的java程序,给满分,否则0分 ~~~b 定义一个数组,要求通过键盘录入数组的长度和数组中各个元素的值,把最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。 ~ 参考程序如下: import java.util.*; public class EX16 { public static void main(String[] args) { int i, min, max, n, temp1, temp2; int a[]; System.out.println(\输入数组的长度:\ Scanner keyboard = new Scanner(System.in); n = keyboard.nextInt(); a = new int[n]; for (i = 0; i < n; i++) { System.out.print(\输入第\个数据\ a[i] = keyboard.nextInt(); } max = 0; min = 0; // 设置两个标志,开始都指向第一个数 for (i = 1; i < n; i++) { if (a[i] > a[max]) max = i; // 遍历数组,如果大于a[max],就把他的数组下标赋给max if (a[i] < a[min]) min = i; // 同上,如果小于a[min],就把他的数组下标赋给min } // 以上for循环找到最大值和最小值,max是最大值的下标,min是最小值的下标 temp1 = a[0]; temp2 = a[min]; // 这两个temp只是为了在交换时使用 a[0] = a[max]; a[max] = temp1; // 首先交换a[0]和最大值a[max] if (min != 0) { // 如果最小值不是a[0],执行下面 a[min] = a[n - 1]; a[n - 1] = temp2; // 交换a[min]和a[n-1] } else { // 如果最小值是a[0],执行下面 a[max] = a[n - 1]; a[n - 1] = temp1; } for (i = 0; i < n; i++) { // 输出数组 System.out.print(a[i] + \ } } } 评分标准: 1、写出能完成题目要求功能的、可正常运行的java程序,给满分,否则0分 ~~~b 定义一个Person类,它包括的私有属性有“姓名”和“性别”,还有构造方法和设置和返回Person对象的“姓名”和“性别”的方法。为Person类派生出一个子类Student类,为Student子类添加两个私有属性年龄和成绩等级(用A,B,C,D,E表示),在子类中打印出学生的姓名、性别、年龄及成绩等级。编写一个测试类,创建一个Student类对象,输出学生的各项信息。 ~ 参考程序如下: class Person{ private String name; private String sex; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } Person(String name,String sex){ this.name=name; this.sex=sex; } public String toString(){ String s=name+\ return s;