单选题应用程序的main方法中有以下语句,则输出的结果是( )。 Hashtable hashtable=new Hashtable(); hashtable.put("100","aaa"); hashtable.put("200","bbb"); hashtable.put("300","ccc"); System.out.println(hashtable.get("300").toString() + hashtable.get("200").toString() + hashtable.get("100").toString()); A.aaa B.bbb C.ccc D.cccbbbaaa
单选题return语句:______ A.只能让方法返回数值 B.方法都必须含有 C.方法中可以有多句return D.不能用来返回对象
单选题下面那些方法不是接口Collection中已声明的方法______? A.添加元素的add(Object obj) 方法 B.删除元素的remove(Object obj)方法 C.得到元素个数的length( )方法 D.返回迭代器的iterator( )方法,迭代器用于元素遍历
问答题import java.awt.*; public class abc public static void main(String args[]) new FrameOut(); class FrameOut extends Frame // Frame为系统定 Button btn; // 义的窗框类 FrameOut( ) super("按钮"); btn = new Button("按下我"); setLayout(new FlowLayout( )); add(btn); setSize(300,200); show( );
问答题简述Java中异常处理的机制?
问答题import java.io.* ; public class Reverse public static void main(String args[ ]) int i , n =10 ; int a[ ] = new int[10]; for ( i = 0 ; i < n ; i ++ ) try BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); a[i] = Integer.parseInt(br.readLine( )); // 输入一个整数 catch ( IOException e ) ; for ( i = n-1 ; i >= 0 ; i ―― ) System.out.print(a[i]+" "); System.out.println( );
问答题编写一个完整的Java Applet 程序使用复数类Complex验证两个复数 1+2i 和3+4i 相加产生一个新的复数 4+6i 。 复数类Complex必须满足如下要求: (1) 复数类Complex 的属性有: RealPart : int型,代表复数的实数部分 ImaginPart : int型,代表复数的虚数部分 (2) 复数类Complex 的方法有: Complex( ) : 构造函数,将复数的实部和虚部都置0 Complex( int r , int i ) : 构造函数,形参 r 为实部的初值,i为虚部的初值。 Complex complexAdd(Complex a) : 将当前复数对象与形参复数对象相加,所得的结果仍是一个复数值,返回给此方法的调用者。 String ToString( ) : 把当前复数对象的实部、虚部组合成 a+bi 的字符串形式,其中a 和 b分别为实部和虚部的数据。
问答题阅读下面的程序代码,并回答问题(①问3分,②问3分,共6分)。 String s1 = new String("abcde"); String s2 = new String("abcde"); boolean b1= s1.equals(s2); boolean b2 = s1== s2; System.out.print(b1+" "+b2); ①程序段执行后,在命令行的输出结果如何? ②解释输出(1)的结果的原因?
问答题请简述重载和重写的区别?
问答题阅读下面的程序,回答问题(①问3分,②问3分,共6分)。。 import java.util.*; public class T public static void main(String args[]) Set set = new TreeSet______; set.add(new Integer(10)); set.add(new Integer(5)); set.add(new Integer(15)); set.add(new Integer(5)); set.add(new Integer(10)); System.out.println("size = " + set.size______); Iterator it=set.iterator______; while(it.hasNext______) System.out.print(it.next______+" "); ①程序运行后输出的结果如何? ②说明java中的集合(Set接口)和映射(Map接口)的主要区别。
问答题import java.io.* ; public class abc public static void main(String args[ ]) int i , s = 0 ; int a[ ] = 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 ; for ( i = 0 ; i < a.length ; i ++ ) if ( a[i]%3 = = 0 ) s += a[i] ; System.out.println("s="+s);
问答题import java.io.*; public class abc public static void main(String args[]) SubClass sb = new SubClass( ); System.out.println(sb.max( )); class SuperClass int a = 10 , b = 20 ; class SubClass extends SuperClass int max( ) return ((a>b)?a:b);
问答题public class Sum public static void main( String args[ ]) double sum = 0.0 ; for ( int i = 1 ; i <= 100 ; i + + ) sum += 1.0/(double) i ; System.out.println( "sum="+sum );
问答题编写一个Frame框架应用程序,要求如下: (1) 在窗口设置两个菜单“文件”、“编辑” (2) 在“文件”菜单里添加三个菜单项“打开”、“保存”、“关闭” (3) 在“编辑”菜单里添加两个菜单项“复制”、“粘贴” (4) 点击关闭菜单项时,使程序关闭。
问答题什么是继承?
问答题按以下要求编写程序 (1) 编写Animal接口,接口中声明run______ 方法 (2) 定义Bird类和Fish类实现Animal接口 (3) 编写Bird类和Fish类的测试程序,并调用其中的run______方法
问答题import java.io.* ; public class abc public static void main(String args[ ]) ) System.out.println("a="+a+"/nb="+b); class SubClass extends SuperClass int c; SubClass(int aa,int bb,int cc) super(aa,bb); c=cc; class SubSubClass extends SubClass int a; SubSubClass(int aa,int bb,int cc) super(aa,bb,cc); a=aa+bb+cc; void show() System.out.println("a="+a+"/nb="+b+"/nc="+c);
问答题import java.io.*; public class abc public static void main(String args[ ]) AB s = new AB("Hello!","I love JAVA."); System.out.println(s.toString( )); class AB String s1; String s2; AB( String str1 , String str2 ) s1 = str1; s2 = str2; public String toString( ) return s1+s2;
问答题阅读下面的程序,并回答问题(①问3分,②问3分,共6分)。 import java.io.*; public class Test public static void main(String args[]) throws IOException BufferedReader buf=new BufferedReader( new InputStreamReader(System.in)); while(true) String str = buf.readLine(); if(str.equals("quit")) break; int x=Integer.parseInt(str); System.out.println(x*x); 编译运行上面的程序: ①从键盘输入10,回车后输出的结果如何? ②从键盘输入exit,回车后程序能正确执行吗?为什么?
问答题阅读下面的程序,回答问题。 import java.awt.*; import javax.swing.*; public class T extends JFrame public T ______ super("GridLayout"); Container con=this.getContentPane______; con.setLayout(new GridLayout(2,3)); con.add(new JButton("a")); con.add(new JButton("b")); con.add(new JButton("c")); con.add(new JButton("d")); con.add(new JButton("e")); con.add(new JButton("f")); setSize(200, 80); setVisible(true); public static void main(String args[]) new T______; ①画图表示程序运行后的图形界面。 ②如果程序通过实现某个接口处理按钮的动作事件,则该接口名为何?接口中的方法头声明如何?
