//打印1000之内的完数(一个数如果恰好等于除它本身外的因子之和,这个数就称为完数//例如6=1+2+3,6的因子是1,2,3)。public class Wanshu{public static void main (String args[ ]){int sum,i,j;for(i=1;i<=1000;i++){for(j=1,sum=0;j<=i/2;j++){(1) {sum=sum+j;}}if(2) {System.out.printf("%8d是一个完数%n",i);}}}}
查看答案
//线程A等待线程B的执行public class Dengdai{public static void main(String args[ ]){KThread a=new KThread ();a.threadA.start();}}class KThread implements Runnable{Thread threadA,threadB;String content[ ]={"今天晚上,","六点钟开始","在201实验室,","全班同学","上java实验!"};KThread(){(1)(2)threadB.setName("老师");}public void run(){if(Thread.currentThread()==threadA){System.out.println("我等"+threadB.getName()+"讲完我在提问!");threadB.start();while(threadB.isAlive()==false){}try{ (3) //线程threadA开始等待threadB结束}catch(InterruptedException e){}System.out.printf("\n老师:\"这个问题该怎么解决,谢谢老师\"");}else if(Thread.currentThread()==threadB){System.out.println(threadB.getName()+"说:");for(int i=0;i
写出下列程序段的运行结果class Parent {String one, two;public Parent(String a, String b){one = a;two = b;}public void print(){ System.out.println(one); }}public class Child extends Parent {public Child(String a, String b){super(a,b);}public void print(){System.out.println(one + " to " + two);}public static void main(String args[]){Parent p = new Parent("south", "north");Parent t = new Child("east", "west");p.print();t.print();}}
写出下列程序段的运行结果class change{void changeint(int x){x++;} public static void main(String args[]){int a=2;System.out.println("Before changed:"+"a="+a);change cxz=new change();cxz.changeint(a);System.out.println("After changed:"+"a="+a);}}
写出下列程序段的运行结果abstract class Shape {abstract void display();}class Circle extends Shape {void display() {System.out.println("Circle");}}class Rectangle extends Shape {void display() {System.out.println("Rectangle");}}class Triangle extends Shape {void display() {System.out.println("Triangle");}}public class AbstractClassDemo{public static void main(String args[]){(new Circle()).display();(new Rectangle()).display();(new Triangle()).display();}}