多选题public class Threads 1 {  intx=0;  public class Runner implements Runnable {  public void run() {  int current = 0;  for(int=i=0;i4;i++){  current = x;  System.out.print(current + “, “);  x = current + 2;  }  }  }  public static void main(String[] args) {  new Threads1().go();  }  public void go() {  Runnable r1 = new Runner();  new Thread(r1).start();  new Thread(r1 ).start();  }  }  Which two are possible results?()A0, 2, 4, 4, 6, 8, 10, 6,B0, 2, 4, 6, 8, 10, 2, 4,C0, 2, 4, 6, 8, 10, 12, 14,D0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,E0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

多选题
public class Threads 1 {  intx=0;  public class Runner implements Runnable {  public void run() {  int current = 0;  for(int=i=0;i<4;i++){  current = x;  System.out.print(current + “, “);  x = current + 2;  }  }  }  public static void main(String[] args) {  new Threads1().go();  }  public void go() {  Runnable r1 = new Runner();  new Thread(r1).start();  new Thread(r1 ).start();  }  }  Which two are possible results?()
A

0, 2, 4, 4, 6, 8, 10, 6,

B

0, 2, 4, 6, 8, 10, 2, 4,

C

0, 2, 4, 6, 8, 10, 12, 14,

D

0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,

E

0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,


参考解析

解析: 暂无解析

相关考题:

下面程序的输出结果是( )。 public class Sun { public static void main(String args[ ]) { int x=0; for(int i=1;i<=4;i++) { x=4; for(int j=1;j<=3;j++) { x=3; for(int k=1;k<=2;k++) { x-x+6; } } } System.out.println(x); } }A.7B.15C.157D.538

下列程序打包到example包,main方法调用线程类输出0~9这10个数,请填写横线处的内容。注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。______interface MyInterface{public abstract void print(int n);}class Mythread extends Thread ______ MyInterface{public void run(){for(int i = 0; i < 10; i++)this.print(i);}public void print(int n){System.out.print(n +" ");}}public class Example1_6{public static void main(String argv[]){Mythread th = new Mythread();______}}

下面程序创建了一个线程并运行,请填空,使程序完整。public class ThreadTest {public static void main (String[] args) {Hello h=Hew Hello ();【 】t.start ();}}class Hello implements Runnable {int i;public void run () {while(true) {System.out.println("Hello" +i++);if(i==5) break;}}}

本题中,鼠标在窗口中单击一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。 import java.awt.*; import java.awt.event.*; import javax swing.*; class MousePanel extends JPanel extends MouseMo- tionListener {public MousePanel {addMouseListener(new MouseAdapter {public void mousePressed(MouseEvent evt) {int X=evt.getX; int Y=evt.getY; current=find(x,y); if(current0) add(x,y); } public void mouseClicked(MouseEvent evt) {int X=evt.getX; int Y=evt.getY; if(evt.getClickCount=2) {remove(current); } } }); addMouseMotionListener(this); } public void paintComponent(Graphics g) {super.paintComponent; for(int i=0;insquares;i++) draw(g,i); } public int find(int X,int y) (for(int i=0;insquares;i++) if(squares[i].x-SQUARELENGTH/2= x X=squares[i].x+SQuARELENGTH/2 squares[i].Y-SQUARELENGTH/2 =Y y=squares[i].Y+SQUARELENGTH /2) return i ; return-1 ; } public void draw(Graphics g,int i) {g.drawRect(squares[i].X-SQUARE- LENGTH/2。 squares[i].Y-SQUARELENGTH/2, SQUARELENGTH, SQUARELENGTH); } public void add(int X,int Y) {if(nsquaresMAXNSQUARES) {squares[nsquares]=new Point(x,y); current=nsquares ; nsquares++; repaint; } } public void remove(int n) {if(n0 ‖ n=nsquares)return; Nsquares- -; squares[n]=squares[nsquares]; if(current= =n)current= -l; repaint; } public void mouseMoved(MouseEvent evt) {} public void mouseDragged(MouseEvent evt) {} private static final int SQUARELENGTH=10: private static final int MAXNSQUARES=100; private Point[]squares=new Point[MAX- NSQUARES]; private int nsquares=0; private int current=-l; } class MouseFrame. extends JFramc {public MouseFrame {setTitle("java3"); setSize(300,200); addWindowListener(new WindowAdapter {public void windowClosing(WindowEvent e) {System.exit(0); } }); Container contentPane=getContentPane; contentPane.add(MousePanel); } } public class java3 {public static void main(String[]args) {JFrame. frame=new MouseFrame; frame.show; } }

下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new TeA.0B.1C.2D.3

下列代码的执行结果是public class Test{ public int aMethod(){ static int i=0; i++; System.out.println(i); } public static void main(String args[]){ Test test= new Test(); test. aMethod(); }}A.编译错误B.0C.1D.运行成功,但不输出

下列程序执行后的结果为______。 public class exl2 { public static void main(string[] args) { int n=4; int x=0; do{ System.out.print(n); }while (x++<n--); } }A.12B.432C.43D.4

下面代码的运行结果是 public class Test{ public static void main(String args[]){ for(int i=0; i<3;i++){ if(i<2) continue; System.out.println(i); } } }A.0B.1C.2D.3

在下面程序的下画线处应填入的选项是 public class Test______{ public static void main(String args[]) { Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run() { for(int i=0;i<5;i++) System.out.println("i="+i); } }A.implements RunnableB.extends ThreadC.implements ThreadD.extends Runnable

interface A{int x = 0;}class B{int x =1;}class C extends B implements A {public void pX(){System.out.println(x);}public static void main(String[] args) {new C().pX();}}

下列程序执行后的结果是______。public class ex24{public static void main(String[] args){int j=10;a1: for(int i=3;i>0;i--){j-=i;int m=l;a2: while (m<j){if (i<=m)continue a1;j/=m++;}}System.out.println(j);}}下列嵌套的循环程序执行后,结果是______。 public class ax25 { public static void main(String[] args) { int sum=0; for(int i=0;i<=5;i++) { for(int j=10;j>3*i;j--) { sum+=j*i; } } System.out.println(sum); } }A.136B.127C.147D.153

下列程序输出结果为( )。public class test { public static void main(String args[]) { int a=0; outer: for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { if(j>i) { continue outer; } a++; } } System.out.println(a); }}A.0B.2C.3D.4

本题的功能是监听鼠标的操作。鼠标置于窗口中单击时(左键或右键),在单击的地方会画一个小矩形,如果将鼠标置于小矩形上,则鼠标光标状态改为小十字,按下鼠标左键可拖曳,双击鼠标左键(或右键)时,小矩形消失。 import java.awt.*; import java.awt.event.*; import java.util.*; import java.awt.geom.*; import javax.swing.*; public class java3 { public static void main(String[]args) { MouseFrame. frame=new MouseFrame: frame.setDefaultCloseOperation(JFrame.EXIT_ oN_CLOSE); frame.show; } } class MouseFrame. extends JFrame { public MouseFrame { setTitle("java3"); setSize(DEFAULT WIDTH, DEFAULT HEIGHT): MousePanel panel=new MousePanel; Container contentPane=getContentPane; contentPane.add(panel); } public static final int DEFAULT_WIDTH=300; public static final int DEFAULT_HEIGHT=200; } class MousePanel extends JPanel { public MousePanel { squares=new ArrayList; current=null: addMouseListener(new MouseHandler); addMouseMotionListener(new MouseMotionHan- dler); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2=(Graphics2D)g; for(int i=0;isquares.size;i++) g2.draw((Rectangle2D)squares.get(i)); } public void find(Point2D p) { for(int i=0;isquares.size;i++) { Rectangle2D r=(Rectangle2D)squares.get(i); if(r.contains(p))return r; } return null: } public void add(Point2D p) { double x=P.getX; double Y=P.getY: current=new Rectangle2D.Double( x-SIDELENGTH/2. y-SlDELENGTH/2. S1DELENGTH, SIDELENGTH); squares.add(current); repaint; } public void remove(Rectangle2D s) { if(S= =null)return: if(S= =current)current=null; squares.remove(s): repaint; } private static final int SIDELENGTH=10: private ArrayList squares; private Rectangle2D current; private class MouseHandter extends MouseAction- Listener { public void mousePressed(MouseEvent event) { current=find(event.getPoint); if(current= =null) add(event.getPoint); } public void mouseClicked(MouseEvent event) { current=find(event.getPoint); if(current!=nullevent.getClickCount =2) remove(current); } } private class MouseMotionHandler implements Mouse- MotionListener { public void mouseMoved(MouseEvent event) { if(find(event.getPoint)= =null) setCursor(Cursor.getDefaultCursor); else setCursor(Cursor.getPredefinedCursor (Cursor.CROSSHAIR_CURSOR)); } public void mouseDragged(MouseEvent event) { if(current!=null) { int x=event.getX: int Y=event.getY; 、 current.setFrame( x-SIDELENGTH/2, Y-SlDELENGTH/2. SIDELENGTH, SIDELENGTH); repaint; } } } }

阅读下面的程序public class Test {public static void main(String[] args) {for(int x = 0 ; x A.跳出循环,无输出B.0121C.01D.0123

( 30 )在程序的下划线处应填入的选项是public class Test _________{public static void main(String args[]){Test t = new Test();Thread tt = new Thread(t);tt.start();}public void run(){for(int i=0;i5;i++){system.out.println( " i= " +i);}}}A ) implements RunnableB ) extends ThreadC ) implements ThreadD ) extends Runnable

Which line contains a constructor in this class definition?()   public class Counter { // (1)   int current, step;   public Counter(int startValue, int stepValue) { // (2)   set(startValue);   setStepValue(stepValue);  }   public int get() { return current; } // (3)   public void set(int value) { current = value; } // (4)   public void setStepValue(int stepValue) { step = stepValue; } // (5)  }  A、Code marked with (1) is a constructorB、Code marked with (2) is a constructorC、Code marked with (3) is a constructorD、Code marked with (4) is a constructorE、Code marked with (5) is a Constructor

class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()  A、 0B、 1C、 2D、 Compilation fails.

public class TestOne implements Runnable {  public static void main (String[] args) throws Exception {  Thread t = new Thread(new TestOne());  t.start();  System.out.print(”Started”);  t.join();  System.out.print(”Complete”);  }  public void run() {  for (int i= 0; i 4; i++) {   System.out.print(i);  }  }  }  What can be a result?()A、 Compilation fails.B、 An exception is thrown at runtime.C、 The code executes and prints “StartedComplete”.D、 The code executes and prints “StartedComplete0123”.E、 The code executes and prints “Started0l23Complete”.

public class Threads 1 {  intx=0;  public class Runner implements Runnable {  public void run() {  int current = 0;  for(int=i=0;i4;i++){  current = x;  System.out.print(current + “, “);  x = current + 2;  }  }  }  public static void main(String[] args) {  new Threads1().go();  }  public void go() {  Runnable r1 = new Runner();  new Thread(r1).start();  new Thread(r1 ).start();  }  }  Which two are possible results?()A、 0, 2, 4, 4, 6, 8, 10, 6,B、 0, 2, 4, 6, 8, 10, 2, 4,C、 0, 2, 4, 6, 8, 10, 12, 14,D、 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,E、 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()  A、 0B、 1C、 2D、 Compilation fails.

public class TestSeven extends Thread {  private static int x;  public synchronized void doThings() {  int current = x;  current++;  x = current;  }  public void run() {  doThings();  }  }  Which is true?() A、 Compilation fails.B、 An exception is thrown at runtime.C、 Synchronizing the run() method would make the class thread-safe.D、 The data in variable “x” are protected from concurrent access problems.E、 Declaring the doThings() method as static would make the class thread-safe.F、 Wrapping the statements within doThings() in a synchronized(new Object()) {} block would make the class thread-safe.

public class TestFive {  private int x;  public void foo() {  int current = x;  x = current + 1;  }  public void go() {  for(int i=0;i5;i++) {  new Thread() {  public void run() {  foo();  System.out.print(x + “, “);  } }.start();  }}}  Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()A、 Move the line 12 print statement into the foo() method.B、 Change line 7 to public synchronized void go() {.C、 Change the variable declaration on line 3 to private volatile int x;.D、 Wrap the code inside the foo() method with a synchronized( this ) block.E、 Wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.

class super (   public int I = 0;   public super (string text) (   I = 1   )   )     public class sub extends super (   public sub (string text) (   i= 2   )   public static void main (straing args) (  sub sub = new sub (“Hello”);   system.out. PrintIn(sub.i);  )   )   What is the result?()A、 Compilation will fail.B、 Compilation will succeed and the program will print “0”C、 Compilation will succeed and the program will print “1”D、 Compilation will succeed and the program will print “2”

单选题public class TestOne implements Runnable {  public static void main (String[] args) throws Exception {  Thread t = new Thread(new TestOne());  t.start();  System.out.print(”Started”);  t.join();  System.out.print(”Complete”);  }  public void run() {  for (int i= 0; i 4; i++) {   System.out.print(i);  }  }  }  What can be a result?()A Compilation fails.B An exception is thrown at runtime.C The code executes and prints “StartedComplete”.D The code executes and prints “StartedComplete0123”.E The code executes and prints “Started0l23Complete”.

单选题class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()A 0B 1C 2D Compilation fails.

单选题public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()A 0B 1C 2D Compilation fails.

多选题public class TestFive {  private int x;  public void foo() {  int current = x;  x = current + 1;  }  public void go() {  for(int i=0;i5;i++) {  new Thread() {  public void run() {  foo();  System.out.print(x + “, “);  } }.start();  }}}  Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()AMove the line 12 print statement into the foo() method.BChange line 7 to public synchronized void go() {.CChange the variable declaration on line 3 to private volatile int x;.DWrap the code inside the foo() method with a synchronized( this ) block.EWrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.

多选题public class Threads 1 {  intx=0;  public class Runner implements Runnable {  public void run() {  int current = 0;  for(int=i=0;i4;i++){  current = x;  System.out.print(current + “, “);  x = current + 2;  }  }  }  public static void main(String[] args) {  new Threads1().go();  }  public void go() {  Runnable r1 = new Runner();  new Thread(r1).start();  new Thread(r1 ).start();  }  }  Which two are possible results?()A0, 2, 4, 4, 6, 8, 10, 6,B0, 2, 4, 6, 8, 10, 2, 4,C0, 2, 4, 6, 8, 10, 12, 14,D0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,E0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,