网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

给定如下Java代码片段,则下列调用方法正确的是()。 Public int count (int i) throws Exception { if (i==0) throw new Exception(“参数不正确!”); return 20/i; }

A.public void useCount(){ count(0); }

B.public void useCount() throws Exception{ count(0); }

C.public void useCount(){ try { count(10); }catch(ArithmeticException e){} }

D.public void useCount(){ try{ count(10); } }


参考答案和解析
public void useCount() throws Exception{ count(0); }
更多 “给定如下Java代码片段,则下列调用方法正确的是()。 Public int count (int i) throws Exception { if (i==0) throw new Exception(“参数不正确!”); return 20/i; }A.public void useCount(){ count(0); }B.public void useCount() throws Exception{ count(0); }C.public void useCount(){ try { count(10); }catch(ArithmeticException e){} }D.public void useCount(){ try{ count(10); } }” 相关考题
考题 有如下程序#includeusing namespace std;int i=1;class Fun{public;static int i;int value(){return i-1}int value ()const{return i+1;}};int Fun;;i=2;int main(){int i=3;Fun Fun1const Fun fun2;return 0;}若程序的输出结果是:123则程序中下划线处遗漏的语句是______。A.coutB.coutC.coutD.cout

考题 下面程序的运行结果是【】。 inChlde using namespace std; class count { static int n; 下面程序的运行结果是【 】。inChlde<iOStream>using namespace std;class count{static int n;public:count(){n++;}static int test(){for(int i=0:i<4;i++)n++;return n;}};int count::n=0;int main(){cout<<COUnt::test()<<" ";count c1, c2;cout<<count::test()<<end1;return 0;}

考题 若类A和类B的定义如下:includeclass A{int i,j;public:int geti(){return i;}};class 若类A和类B的定义如下: #include<malloc.h> class A { int i,j; public: int geti() { return i; } }; class B:public A { int k; public: void make() { k=i*j; } }; 则上述定义中非法的表达式是( )。A.k=i*jB.int k;C.return i;D.void make();

考题 若类A和类B的定义如下class A{int i,j;public:int geti( ){return i;}};class B:public A{int k:public:void make( ){k=i*j;}};则上述定义中非法的语句是A.k=i*jB.int k;C.return i;D.void make()

考题 本题中,鼠标在窗口中单击一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。 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; } }

考题 ( 20 )在下列程序的空白处,应填入的正确选项是import java.io.*;Public class writeInt{Public static void main(string[ ] a) {Int[ ] myArray = {10,20,30,40};try{DataOutputSystem dos= new DataOutputSystem( new FileOutputSystem( “ ints.dat ” ) ) ;for ( int i=0 ; ImyArray.length ; i++ )dos 。 writeInt ( myArray[i] ) ;dos.System.out.println( “ Have written binary file ints.dat ” );}Catch(IOException ioe){ System.out.println( “ IO Exception ” );}}}A)start( )B)close( )C)read( )D)write( )

考题 下面程序的运行结果是【】。 include using namespace std; class count{ static int n; 下面程序的运行结果是【 】。include <iostream>using namespace std;class count{static int n;public:count(){n++;}static int test(){for(int i=0;i<4;i++)n++;return n;}};int count::n = O;int main(){cout<<count:: test()<<" ";count c1, c2;cout<<count:: test()<<endl;return 0;}

考题 有如下程序:includeusing namespace std;class TestClass{static int i;public:TestC 有如下程序: #include<iostream> using namespace std; class TestClass{ static int i; public: TestClass(){i++;} ~TestClass(){i--;} static int getVal(){return i;} }; int TestClass::i=0; void f(){TestClass obj2;cout<<obj2.getVal();} int main(){ TestClass obj 1; f(); TestClass *obj3=new TestClass;cout<<obj3->getVal(); delete obj3;cout<<TestClass::getVal(); return 0; } 程序的输出结果是( )。A.232B.221C.222D.231

考题 若类A和类B的定义如下: class A { int i,j; public: int geti () { return i; } }; class B : public A { int k; public: void make () { k=i*j; } }; 则上述定义中非法的语句是A.k=i*j;B.int k;C.return i;D.void make()

考题 若类A和类B的定义如下:includeclass A{int i*j;public:int geti(){return i;}};class 若类A和类B的定义如下: #include<malloc.h> class A { int i*j; public: int geti() { return i; } }; class B: public A { int k; public: void make() { k=i*j; } ); 则上述定义中非法的表达式是( )。A.k=i*j;B.int k;C.return i;D.void make();

考题 有如下程序:includeusing namespace std;int i=1;class Fun{public:static int i;int 有如下程序: #include<iostream> using namespace std; int i=1; class Fun { public: static int i; int value(){return i-1;} int value()const{return i+1;} }; int Fun::i=2; int main() { int i=3; Fun fun 1; const Fun fun2; ______ return 0; } 若程序的输出结果是: 123 则程序中横线处的语句是( )。A.cout<<fun1.value()<<Fun::i<<fun2.value();B.cout<<Fun::i<<fun1.value()<<fun2.value();C.count<<fun.value()<<fun2.value()<<Fun::i;D.cout<<fun2.value()<<Fun::i<<fun1.value();

考题 阅读下面程序 import java.io.*; public class ByteStreamTest { public static void main(String[] A) { int [] myArray = {10,20,30,40 }; try{ DataOutputStream dos = new DataOutputStream ( new______ ("ints.dat")); for (int i=0; i<myArray, length; i++) dos.writelnt( myArray[i] ); dos.close(); System.out.println("Have written binary file ints.dat"); } catch (IOException ioe){ Sy stem.out.println("IO Exception"); } } } 为保证程序正确运行,在程序中下划线处应填入的代码是A.FileOutputStreamB.ByteArrayOutputStreamC.BufferedOutputStreamD.FileWriter

考题 阅读下面写文件的程序 import java. io. *; public class WriteFile{ public static void main(String[]A) { int[]myArray={10,20,30,40}; try{ FileOutputStream f=new FlieOutStream("ints. dat"); DataOutputStream______=new DataOutputStream(f); for(int i=0; i<myArray. length; i ++) dos. writeInt(myArray[i]); dos. close(); System. out. prinfln("Have written binary file ints. dat"); } catch(IOException ioe){ System. out. println("IO Exception"); } } 在程序下画线处填入的正确选项是A.myArrayB.dosC.ioeD.ints

考题 若类A和类B的定义如下: class A { int i,j; public: int geti() { return i; } }; class B: public A { int k; public: void make() { k=i*j } }; 则上述定义中A.k=i*j;B.int k;C.return i;D.void make()

考题 选择正确的语句填在下列程序的横线处,使程序正常运行。 package ch1; import java. io. *; import j ava. util. *; class C45 implements Seritizable ______Public Thread t = new Thread(new T45(), "t"); public intcnt = 0; public C45() { t. start ( ) class T45 implements Runnable public int[] a = new int[4]; public void run() { for(int i - 0; i < 4; i++) { a[i] - i +4; } } } public class ex45 { static String fileName = "ch1\\file45.txt"; public static void main(String[] args) throws Exception { C45 bj = new C45 (); FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream os = new ObjectOutputStream(fos); oos. writeObject (obj); oos.clese (); fos.close (); System. out, println (obj . toString ( ) ); } }A.transientB.protectedC.packageD.final

考题 有以下程序:include using namespace std;class count{ static int n;public: count 有以下程序: #include <iostream> using namespace std; class count { static int n; public: count ( ) { n++; } static int test() { for (int i = 0; i < 4; i++ ) n++; return n; } }; int count :: n = 0; int main() { cout<<count :: test()<<" "; count c1, c2; cout<<count :: test()<<end1; return 0; } 执行后的输出结果是( )。A.4 10B.1 2C.22D.24

考题 阅读以下说明和 Java 代码,填补代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 设计 RGB 方式表示颜色的调色板,进行绘图。其类图如图 6-1 所示。该程序的 Java代码附后。图6-1 类图【Java 代码】 //颜色类 class MyColor { private int red ,green, blue; public MyColor( ) { red = o; green = 0; blue = 0; } public MyColor(int red ,int green ,int blue) { this.red = red; this.green = green; this.blue = blue; } //其他方法略 public String toString( ) { return Red: + red + \tGreen: + green + \tBlue + blue; } } //调色板类 class Palette { public int number; / /颜色数 private (1)palette; //颜色表 public Palette( ) { number = 256; palette = new MyColor[number); } public Palette(MyColor[] palette ,int number) { (2)= number; (3)= palette; } //其他方法略 public String toString( ) { String str = ; for (int i = 0; i number; i++) { str +=i+ : + palette[i] + \n; } return str; } //绘图类 class Drawing { public (4) int COLORNUMBER = 16; public static void main(String[] args) { Palette palette; int red ,green ,blue; MyColor[] color = new MyColor[COLORNUMBER]; for (int i = 0; i COLORNUMBER; i++) { red = (int) (Math.random( ) * 256); green = (int) (Math.random( ) * 256); blue = (int) (Math.random( ) * 256); color [i] = (5) (red ,green ,blue); } palette = new Palette(color ,COLORNUMBER); System.out.println(palette); } }

考题 在注释//Start For loop 处要插入哪段代码可实现根据变量i的值定位数组ia[]的元素?public class Lin{public void amethod(){int ia[] = new int[4];//Start For loop{ia[i]=i;System.out.println(ia[i]);}}} A. for (int i=0; iB. for (int i=0; iC. for (int i=1; iD. for (int i=0; i

考题 下列程序的输出结果是______。 include class base { int x,y; public: base(int i,i 下列程序的输出结果是______。include<iostream.h>class base{int x,y;public:base(int i,int j){x=i;y=j;}virtual int add( ){return x+y;}};class three:public base{int z;public:three(int i,int j,int k):base(i,j){z=k;)int add( ){return(base::add( )+z);}};void main( ){three*q=new three(10,20,30);cout<<q->add( )<<endl;}

考题 ( 11 )请在下列程序的空白处,填上适当的内容:Import java. awt. *;Import java. util. *;Class BufferTest{Public static void main(string args[])Throws IOException{FileOutputStream unbuf=new FileOutputStream( “ test.one ” ) ;BufferedOutputStream buf=new 【 11 】 (new FileOutputStream( “ test.two ” ));System.out.println( “ write file unbuffered: ” + time(unbuf) + “ ms ” );System.out.println( “ write file buffered: ” + time(buf) + “ ms ” );}Static int time (OutputStream os)Throws IOException{Date then = new Date();for (int i=0; i50000; i++){os.write(1);}}os.close();return(int)(()new Date()).getTime() - then.getTime());}

考题 10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?() A、 StackOverflowErrorB、 NullPointerExceptionC、 NumberFormatExceptionD、 IllegalArgumentExceptionE、 ExceptionlnlnitializerError

考题 给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A } A、public int cal(int x,int y,float z){return 0;}B、public int cal(int x,int y,int z){return 0;}C、public void cal(int x,int z){}D、public viod cal(int z,int y,int x){}

考题 class ThreadExcept implements Runnable {   public void run() { throw new RuntimeException("exception "); }   public static void main(String [] args) {   new Thread(new ThreadExcept()).start();   try {   int x = Integer.parseInt(args[0]);   Thread.sleep(x);   System.out.print("main ");    } catch (Exception e) { }      }  }   和命令行:  java ThreadExcept 1000    哪一个是结果?()  A、 mainB、 编译失败C、 代码运行,但没有输出D、 main java.lang.RuntimeException:exception

考题 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 Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? ()A  0B  3C  Compilation fails.D  An exception is thrown at runtime.

考题 单选题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”.

考题 单选题10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?()A  StackOverflowErrorB  NullPointerExceptionC  NumberFormatExceptionD  IllegalArgumentExceptionE  ExceptionlnlnitializerError

考题 单选题class Computation extends Thread {  private int num;  private boolean isComplete;  private int result;  public Computation(int num) { this.num = num; }  public synchronized void run() {  result = num * 2;  isComplete = true;  notify();  }  public synchronized int getResult() {  while (!isComplete) {  try {  wait();  } catch (InterruptedException e) { }  }  return result;  }  public static void main(String[] args) {  Computation[] computations = new Computation [4];  for (int i = 0; i  computations.length; i++) {  computations[i] = new Computation(i);  computations[i] .start();  }  for (Computation c : computations)  System.out.print(c.getResult() +“ “);  }  }  What is the result?()A  The code will deadlock.B  The code may run with no output.C  An exception is thrown at runtime.D  The code may run with output “0 6”.E  The code may run with output “2 0 6 4‟.F  The code may ruin with output “0 2 4 6”.