}
public static void main(String args[]){ Student student=new student; student.name=”Alisha”; student.id=”C001”; student.display(); } }
2.给出下列的代码,哪行在编译时可能会有错误⑦ ① public void modify(){ ② int i, j, k; i = 100; ④ while ( i > 0 ){ ⑤ j = i * 2;
⑥ System.out.println (\); ⑦ k = k + 1; ⑧ } ⑨ }
3.分析指出以下程序的功能并作出注释,输出结果是 ( 1 ) public class A{
public int hashCode(){return 1;}
public Boolean equals(Object b){return true}
public static void main(String args[]){ Set set=new HashSet(); set.add(new A()); set.add(new A()); set.add(new A());
System.out.println(set.size()); } }
4.分析程序,回答问题。下列程序的运行结果是 ( 25 ) class A{ class Dog{
private String name; private int age; public int step; Dog(String s,int a) {
name=s; age=a; step=0; }
public void run(Dog fast) {
fast.step++; }
}
public static void main (String args[]) {
A a=new A();
Dog d=a.new Dog(\ d.step=25; d.run(d);
5. 如果有这样一个 Java 源文件如下: public class Test {
public static void main(String[] arguments) { System.out.println(\} }
class student {
public void func() {
System.out.println(\} }
阅读程序,回答下面几个问题: (1) 请写出这个文件的完整名称
(2) 请写出在命令行上如何编译这个文件
(3) 请写出这个文件编译后产生几个类文件,它们的完整名称分别是什么? (4) 请写出在命令行上如何运行这个程序? (5)这个程序的运行结果是什么?
6 、以下程序的输出结果为___value is_Hello________________ 。 public class Short{
public static void main(String args[ ]) { StringBuffer s = new StringBuffer(“Hello”);
if((s.length( )>5)&& (s.append(“there”) . equals(“False”))) ;
System.out.println(“value is”+s); } }
7、 读程序,写出正确的运行结果。(2,7,14,12) class test {
public static void main(String[] arg){ int a=1,b=6,c=4,d=2; switch (a++) { case 1: c++; d++; case 2: switch (++b)
{ case 7: c++; case 8: d++; } case 3: c++; d++; break; case 4: c++; d++;
}
System.out.println(a+\} }
8、写出下列程序完成的功能。(Sum= 1.0+1.0/2.0+...+1.0/100.0) 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( \ } } 9、(20)
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); } } 10、写出程序运行结果(s=180) 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(\ } }
11、写出程序运行结果(Hello! I love JAVA.) import java.io.*; public class abc
{ public static void main(String args[ ]) { AB s = new AB(\ 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;} }
12.写出程序运行结果(10,9) public class test { static int m = 9;
public static void main(String[] args) { test fd1 = new test(); fd1.m++;
test fd2 = new test();
System.out.println(fd1.m + “,” + fd2.m); } }
13. 写出程序的输出结果为 。(value is Hello) public class Short{
public static void main(String args[ ]) { StringBuffer s = new StringBuffer(“Hello”);
if((s.length( )>5)&& (s.append(“there”) . equals(“False”))) ;
System.out.println(“value is”+s); }
14. 请说出下列代码的执行结果 (equals): String s = \
String s1 = new String(s);
if (s = = s1) System.out.println(\if (s.equals(s1)) System.out.println(\15. 阅读以下程序,输出结果为 。(1.13) class Q1{
public static void main ( String args[ ] ) { double d=1.23;
Dec dec=new Dec( ); dec.decrement(d);
System.out.println(d); }
classs Dec{
public void decrement(double decMe){ decMe = decMe - 0.1; }
}
16.阅读下列代码,其运行结果是( 10 ) public class Test{
public static void main(String args[]){ int a=025; int b=a>>1;
System.out.println(b); } }
17. 分析本程序的输出 (九九乘法表) public class lianxi16 {
public static void main(String[] args) { for(int i=1; i<10; i++) { for(int j=1; j<=i; j++) {
System.out.print(j + \ if(j*i<10){System.out.print(\}
System.out.println(); } } }
六 . 编写程序题
1. 编程实现软件系统用户登录的用户名和口令检查,两者正确,欢迎进入,三次机会,若输入错误,提出警告,退出系统。 import java.io.File;
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Test {
ArrayList user_list = new ArrayList();
//将user_list存入文件
public void writeData() throws Exception {
FileOutputStream fo=new FileOutputStream(\
ObjectOutputStream fobj = new ObjectOutputStream(fo); fobj.writeObject(user_list); fobj.close();