JAVA习题(JAVASE)
javase练习题
javase练习题一、基础知识篇1. Java基本数据类型有哪些?分别写出它们的默认值。
2. 什么是封装?简述封装的优点。
3. 请写出Java中的四种访问修饰符,并说明它们的访问权限。
4. 什么是构造方法?它与普通方法的区别是什么?5. 在Java中,如何实现方法的重载和重写?二、面向对象篇2. 如何实现一个简单的Java类,包含两个属性和一个方法?3. 简述Java中的继承机制及其作用。
4. 什么是接口?与抽象类有什么区别?5. 请举例说明Java中的多态性。
三、集合框架篇1. Java集合框架中常用的集合类有哪些?2. 请简述ArrayList和LinkedList的区别。
3. 什么是HashMap?它的工作原理是什么?4. 请解释HashSet和TreeSet的区别。
5. 如何遍历一个List集合?四、异常处理篇1. 什么是异常?Java中的异常分为哪几类?2. 请举例说明trycatchfinally语句的使用方法。
3. 什么是自定义异常?如何创建和使用自定义异常?4. 请简述Java异常处理机制的作用。
int a = 10;int b = 0;int result = a / b;五、IO流篇1. 请简述Java IO流的分类。
2. 如何实现文件复制功能?3. 请解释字节流和字符流的区别。
4. 什么是序列化和反序列化?如何实现?5. 请举例说明Java中的文件操作。
六、多线程篇1. 什么是线程?线程和进程有什么区别?2. 请简述线程的生命周期。
3. 如何创建一个线程?有哪几种方式?4. 什么是线程同步?为什么需要线程同步?5. 请解释线程池的概念及其作用。
七、网络编程篇1. 请简述TCP和UDP协议的区别。
2. 如何实现一个简单的Socket通信?3. 什么是URL?如何解析一个URL?4. 请简述HTTP协议的工作原理。
5. 如何实现一个简单的HTTP服务器?八、Java新特性篇1. 请列举Java 8中的几个新特性。
JavaSe内部测试笔习题
精心整理《JavaSE》结课笔试注意:1、考试时间120分钟;2、请将答案填写到答题纸上;1、面向对象编程的三大特性是()2、3、4、C)default D)protected5、以下哪种类成员修饰符可以在不同包的子类中访问()A)static B)privateC)default D)protected6、Java语言中哪个包是被自动导入的()A)java.util B)ngC)java.default D)java.io7、以下程序代码中,如何使属性foo可以在方法bar中被直接访问()classTest{publicfloatfoo;8、9、publicstaticvoidmain(Stringargs[]){Strings1="Helloworld";Strings2="Hello";s2=s2+"world";}}A)true B)falseC)编译错误D)Helloworld10、在Java中,如果父类中的某些方法不包含任何逻辑,并且需要由子类重写,11、12、B)数组的元素可以是基本型、引用型或其它数组C)定义数组的同时必须分配内存空间D)一个数组中的所有值必须是相同类型13、下面关于接口说法不正确的是()A)接口的所有方法都是抽象的B)接口所有的方法一定都是public的C)用于定义接口的关键字是implements D)接口是一组行为的集合14、为了区分类中重载的同名不同方法,要求()A)参数的类型或个数不同B)使用不同的参数名C)修改访问权限D)方法返回值数据类型不同15、如果子类覆盖了父类的一个public方法,则此方法在子类中可以使用什么修16、17、}finally{System.exit(0);//程序中止}}}A)testB)finallyC)testfianlly18、C)ArithmeticExceptionD)ArithmeticException和ArrayIndexOutOfBoundsException19、关于异常,下列描述正确的是()A)try代码段和其后跟随的catch代码段之间可以有间隔代码B)每个catch代码段声明其能处理的一种特定类型的异常C)finally代码段在异常出现的情况下不被执行D)finally代码段中不可以有try和catch代码段//X20、关于日期时间说法正确的是()A)类无法表示1970年1月1日00:00:00之前的时间B)要得到日历类的实例,我们唯一的做法是newGregorianCalendar()21、22、23、B)对内容有序的List可以进行二分法查找C)调用indexOf方法查找D)无论是否有序都可以用二分法查找,比线性查找快很多24、如果要按照特定顺序保存元素,应当使用的容器是()A)HashMap B)ArrayListC)JFrame D)TreeSet25、有一个名为myList的ArrayList实例,取得其最后一个元素的方法是()A)myList.get(0); B)myList.get(st());C)myList.get(myList.size()); D)myList.get(myList.size()-1);26、有一个名为myList的ArrayList实例,调用mylist.get(0)的结果是()27、28、returna+2;}publicstaticvoidmain(String[]args){Bb=newB();}}A)编译错误B)运行错误C)1 D)229、当编译并运行下面程序时会出现什么结果()publicclassMyAr{30、31、C)URL和URLConnection D)DNS和HTTPStream32、当编译并运行下面程序时会发生什么结果()publicclassBgroundextendsThread{ publicstaticvoidmain(Stringargv[]){ Bgroundb=newBground();b.run();//start}publicvoidstart(){for(inti=0;i<10;i++){}}}33、ABC、a9897.098D、a98979834、将对象序列化,要实现哪个接口()A)Cloneable B)RunnableC)Serializable D)Comparator35、有以下Java程序代码,运行结果是()publicclassTest{publicstaticStringoutput="";//134publicstaticvoidfoo(inti){try{foo(0);foo(1);}}A)1342 B)123C)134234 D)1342336、在JAVA中,()接口位于集合框架的顶层A)Collection B)CollectionsC)Map D)Set37、启动一个线程,应调用什么方法()38、39、ABCD40、C.JAVA可以多继承D.JAVA的单一继承避免了菱形继承的危险41、下面哪些接口直接继承自Collection接口()(多选)A.ListB.MapC.SetD.Iterator42、研究下面的JAVA代码,输出结果将是()publicclassTestException{publicstaticvoidmain(String[]args){ inta[]={0,1,2,3,4};intsum=0;C.数组下标越界程序结束D.程序结束43、研究下面的JAVA代码,输出结果将是()publicclassTestException{publicstaticvoidmain(String[]args){try{System.exit(0);}finally{}}44、}A.s:cbathis.s:nbas:cbathis.s:nbaB.s:nbathis.s:nbas:nbathis.s:nbaC.s:cbathis.s:nbas:cbathis.s:cbaD.s:nbathis.s:cbas:cbathis.s:cba45、关于sleep和wait方法,下列说法不正确的是()(多选)A.sleep必须使用在同步方法中B.使用wait方法后,线程需要被通知唤醒C.wait方法用于线程之间的通讯D.wait是Thread类的方法46、D47、}}A、用来调用类B中定义的super()方法B、用来调用类C中定义的super()方法C、用来调用类B中的无参构造方法D、用来调用类B中第一个出现的构造方法48、关于线程,以下说法正确的是()(多选)A.sleep方法执行时会释放对象锁。
精选JAVASE综合考试题库188题(含答案)
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set2."以下代码执行结果是?public abstract class Example extends Base {public abstract void method();}class Base {public Base() throws IOException {throw new IOException();}}"答案:A.代码编译失败,因为非抽象类不能被扩展为抽象类B.代码编译失败,因为必须提供一个可以抛出或可以不抛出IOException异常的构造器C.代码编译失败,以in为必须提供一个可以抛出IOException异常或其子类的构造器D.代码编译成功3."现有如下代码:public class Example {public static void main(String[] args) {try {System.out.println(""before"");doRisyThing();System.out.println(""after"");} catch (Exception e) {System.out.println(""catch"");}System.out.println(""done"");}public static void doRisyThing() throws Exception{//this code returns unless it throws an Exception}}该代码可能的执行结果有哪些?"答案:A.before catchB.before after doneC.before catch doneD.before after catch4."以下代码的输出结果是什么?选择所有的正确答案。
javaSE作业
javaSE作业JavaSE测试题⼀、选择题(不定项)1.在JAVA中,下列哪些说法是正确的( A C )A.java源⽂件的扩展名为.javaB.写好的java源程序可以直接运⾏C.编写的源程序必须先编译后才能运⾏D.程序员可以读懂扩展名为.class的⽂件2.下列标识符哪个是合法的( BD )A.classB.$abcC.1234D._name3.下⾯哪些赋值语句是正确的?( ab d)A. long test = 012;B. float f = -412;C. int other = (int) true;D. double d = 0x12345678;E. byte b = 128; -128~1274.在Java中,下列语句不能通过编译的有(b )A. String s= “join”+ 3;B. int a= “join”+3;C. int a= ‘a’+5;D. float f=5+5.5;5.设a = 3,则表达式(--a )< < a的结果为( b )A. 16B. 8C. 24D. 126.下列代码运⾏的结果是(c )public static void main(String[] args) {int x = 4;int y = 5;if(x++>4 & ++y>5) {x++;}System.out.println("x=" + x + ",y=" + y); }A. x=4,y=5B. x=4,y=6C. x=5,y=6D. x=6,y=67.尝试运⾏下⾯的代码会发⽣什么?( b ) public class Test {public static void main(String[] args) { boolean m = true;if (m = false) {System.out.println("true");} else {System.out.println("false");}}}A.输出字符串”true”B.输出字符串”false”C.编译时错误D.运⾏时错误8.编译并运⾏以下代码将发⽣什么? ( e) public static void main(String args[]){ char digit = 'a';for (int i = 0; i < 10; i++){switch (digit){case 'x' :{int j = 0;System.out.println(j);}default :{int j = 100;System.out.println(j);}}}int i = j;System.out.println(i);}A.输出11次100B.输出10次100,然后抛出运⾏期异常C.编译错误,因为变量i不能在main()⽅法中被声明2次D.编译错误,因为变量j不能在main()⽅法中被声明2次E.以上都不对9. class Demo{public static int fun(int c){return c+=2;}public static void main(String[] args){int temp = fun(2);System.out.println(temp);}}打印结果是(b )A. 2B. 4C. 6D. 810.下⾯哪些函数是public void aMethod(){...}的重载函数?(bd )A. void aMethod( ){...}B. public int aMethod(int a, float b){...}C. public void aMethod (){...}D. public float aMethod (int m){…}11.在java中,关于数组描述正确的是( b d )A.数组中的索引下标从1开始B.存储在数组当中的数据都属于同⼀数据类型C.通过数组名.length()能获得数组的长度D.数组的最⼤索引下标是数组的长度减112.下⾯程序的输出结果是什么( d )int[] arr = new int[10];System.out.println(arr[0]);A.编译不通过B.运⾏时出错C.输出nullD.输出013.下⾯哪个语句正确地声明⼀个整型的⼆维数组( c d )A. int a[][] = new int[][];B. int b[10][10] = new int[][];C. int c[][] = new int[10][10];D. int []d[] = new int[10][10];14.以下代码输出是( d )class Demo {public static void main(String[] args) {int i = 0;int sum = 0;while (i <= 10) {i++;if (i % 2 != 0)continue;sum += i;}System.out.println(sum);}}A. 55B. 45C. 35D. 3015.和下⾯代码能完成相同的选项是( b )class Demo {public static void main(String[] args) {int i = 1;int sum = 0;while (i <= 100) {if (i % 2 == 0) {sum = sum + i;}i++;}System.out.println(sum);}}A. for (int x =1; x<=100;x++){ sum=sum+x;}B. for (int x =0; x<=100;x+=2){ sum=sum+x;}C. for (int x =1; x<=100;x+=2){ sum=sum+x;}D.上述全对16.下列有关类、对象和实例的叙述,正确的是哪⼀项?( d )A.类就是对象,对象就是类,实例是对象的另⼀个名称,三者没有差别B.对象是类的抽象,类是对象的具体化,实例是对象的另⼀个名称C.类是对象的抽象,对象是类的具体化,实例是类的另⼀个名称D.类是对象的抽象,对象是类的具体化,实例是对象的另⼀个名称17.下⾯关于java中包的说法正确的是( a,d c )A.在java中可以使⽤import语句导⼊包B.在java中可以使⽤package语句导⼊包C.位于同⼀个包中的类,不需要导包就可以直接访问D.不同的包中可以出现类名相同的类18.下列有关抽象类的叙述正确的是哪项? (c)A.抽象类中⼀定含有抽象⽅法B.抽象类既能被实例化也能被继承C.抽象类的声明必须包含abstract关键字D.抽象类中不能有构造⽅法19.下列有关接⼝的叙述错误的是哪项?( a d )A.接⼝中只能包含抽象⽅法和常量B.⼀个类可以实现多个接⼝C.类实现接⼝时必须实现其中的⽅法D.接⼝不能被继承20.运⾏以下代码⽚段,输出结果是?( d )class X {Y b = new Y();X() {System.out.print("X");}}class Y {Y() {System.out.print("Y");}}public class Z extends X {Y y = new Y();Z() {System.out.print("Z");}public static void main(String[] args) {new Z();}}//静态(初始化⼀次)动态(创建⼀次执⾏⼀次)构造A. ZB. YZC. XYZD. YXYZ21.下列关于类的继承的描述,正确的有( b d )A.⼀个类可以同时继承多个⽗类B.⼀个类可以具有多个⼦类C.⼦类会⾃动拥有⽗类所有的⽅法D.⼀个类继承另⼀个类需要使⽤extends关键字22.下列选项中关于java中this关键字的说法错误的有( ab d )A.this关键字是⼀个对象的引⽤ //本类B.this关键字可以⽤于引⽤当前类以外其他类型的对象C.this可⽤于构造函数中,调⽤类本⾝重载的构造函数,但是必须写在⾸⾏D.this可⽤于静态⽅法中//this属于对对象的调⽤,静态⽅法属于类23.下列关于构造函数的说法正确的是( a b d )A.⽅法名必须与类名相同B.使⽤new关键字创建对象时,java虚拟机会⾃动调⽤构造函数C.我们在定义⼀个类时,必须要声明⾄少⼀个构造函数D.构造函数中不能使⽤return语句24.编译并运⾏以下代码将发⽣什么?( d )class MyClass {int x;MyClass(int i) {x = i;}public static void main(String args[]) {MyClass m1 = new MyClass(100);MyClass m2 = new MyClass(100);if (m1.equals(m2)) {System.out.println("Both are equal");} else {System.out.println("Both are not equal");}}}A.代码编译时报出错误提⽰信息“equals()⽅法未定义”B.编译通过,抛出运⾏期异常.C.输出Both are equal.D.输出Both are not equal25.运⾏以下的main()⽅法,结果是?( a c )1 public static void main(String[] args)2 {3 String myString;4 int x = 100;56 if (x < 100) myString = "x is less than 100";7 if (x > 100) myString = "x is greater than 100";8 System.out.println(myString.length());9 }A.编译时报出错误提⽰信息“变量myString没有被初始化”B.编译通过C.编译未能通过。
JavaSE考试题参考答案
JavaSE考试题(时间150分钟)一.选择题(75分)1.在Java中负责对字节码解释执行的是( B )A.垃圾回收器B.虚拟机C.编译器D.多线程机制2.BufferedReader的父类是( B )A.FileReaderB.ReaderC.PipedReaderD.InputStreamReader3.在读字符文件Post.dat时,使用该文件作为参数的类( A )A.BufferedReaderB.DataInputStreamC.DataOutputStreamD.FileInputStream4.下列不是InputStream子类的是( C )A.FileInputStreamB.ObjectInputStreamC.CharInputStreamD.ZipInputStream5.下列方法中可以用来创建一个新线程的是( D )A.实现ng.Runnable接口并重写start()方法B.实现ng.Runnable接口并重写run()方法C.继承ng.Thread类并重写start()方法D.继承ng.Thread类并重写run()方法6.当启动Applet程序时,首先调用的方法是( B )A.stop()B.init()C.start()D.destroy()7.序列化一个类时,如果要隐藏某个成员,使之在反序列化时不能看到搞成员的真实数据,应当使用的关键字是( C )A.hiddernB.privateC.transientD.destroy8.将键值对(key--value)保存到映射(Map)对象中的方法是( B )。
A.add(Object key,Object value)B.put(Object key,Object value)C.insert(Object key,Object value)D.get(Object key,Object value)9. 一个java Application 运行后,在系统中是作为一个( B )A.线程B.进程C.进程或线程D.不可预知10.下列关于线程调度的叙述中,错误的是:( D)A.调用线程的sleep()方法,可以使比当前线程优先级低的线程获得运行机会B.调用线程的yield()方法,只会使与当前线程相同优先级的线程获得运行机会C.当有比当前线程优先级高的线程出现时,高优先级的线程将抢占CPU并运行D.具有相同优先级的多个线程的调度一定是分时的.11.下列关于线程优先级别的说法中,正确的是( C)A.线程的优先级是不能改变的B.线程的优先级在创建线程时设定C.在创建线程后的任何时候都可以设置D.B,C12.实现一个线程的创建方法有几种( B )A.一种B.二种C.三种D.四种13.下列关于泛型的说法,错误的是( B )A、泛型是一种参数化类型B、可以取代继承机制。
javase考试试题和答案
javase考试试题和答案一、单项选择题(每题2分,共20分)1. Java中,下列哪个关键字用于声明一个类?()A. classB. interfaceC. abstractD. final答案:A2. 在Java中,下列哪个选项是正确的字符串拼接方式?()A. "Hello" + "World"B. "Hello" + 5C. "Hello" + 5.0D. 5 + "Hello"答案:A3. Java中,下列哪个选项是正确的方法重载?()A. public void display() {}public void display(int x) {}B. public void display(int x) {}public void display(double x) {}C. public void display(int x) {}public void display(int x, int y) {}D. public void display() {}public void display() {}答案:C4. Java中,下列哪个选项是正确的继承关系?()A. class A extends B {}B. class A implements B {}C. class A implements B, C {}D. class A extends B, C {}答案:C5. Java中,下列哪个选项是正确的异常处理语句?()A. try { } catch { }B. try { } catch (Exception e) { }C. try { } catch (e) { }D. try { } catch (Exception) { }答案:B6. Java中,下列哪个选项是正确的泛型使用方式?()A. List list = new ArrayList();B. List<String> list = new ArrayList<String>();C. List list = new ArrayList<String>();D. List<String> list = new ArrayList();答案:B7. Java中,下列哪个选项是正确的线程创建方式?()A. Thread thread = new Thread();B. Thread thread = new Thread(Runnable r);C. Thread thread = new Thread(new Thread());D. Thread thread = new Thread(new Runnable() {});答案:D8. Java中,下列哪个选项是正确的集合初始化方式?()A. List list = new ArrayList();B. List list = new LinkedList();C. List list = new Vector();D. List list = new Stack();答案:A9. Java中,下列哪个选项是正确的文件读写方式?()A. FileReader fr = new FileReader("file.txt");B. FileWriter fw = new FileWriter("file.txt");C. BufferedReader br = new BufferedReader(new FileReader("file.txt"));D. BufferedWriter bw = new BufferedWriter(new FileWriter("file.txt"));答案:C10. Java中,下列哪个选项是正确的网络编程方式?()A. ServerSocket serverSocket = new ServerSocket(8080);B. Socket socket = new Socket("localhost", 8080);C. DatagramSocket socket = new DatagramSocket(8080);D. MulticastSocket socket = new MulticastSocket(8080);答案:A二、多项选择题(每题3分,共15分)1. Java中,下列哪些关键字用于修饰类?()A. publicB. abstractC. finalD. strictfp答案:ABCD2. Java中,下列哪些关键字用于修饰方法?()A. publicB. privateC. protectedD. synchronized答案:ABCD3. Java中,下列哪些关键字用于修饰变量?()A. publicB. privateC. protectedD. volatile答案:BCD4. Java中,下列哪些关键字用于修饰接口?()A. publicB. abstractC. finalD. strictfp答案:ACD5. Java中,下列哪些关键字用于修饰异常?()A. tryB. catchC. throwD. throws答案:BCD三、填空题(每题4分,共20分)1. Java中,一个类可以继承________个父类。
javase 选择题
javase 选择题1. Java语言中的关键字不包括A. finalB. publicC. extendD. static答案:C2. 下列哪些修饰符可以用来修饰类?A. abstractB. privateC. finalD. publicE. static答案:ABCD3. 下列哪些不是Java中的基本数据类型?A. charB. booleanC. floatD. string答案:D4. 下列哪些关于Java类和对象的描述是正确的?A. 类是对象的实例,对象是类的实例B. 一个类可以同时继承多个类C. 类可以直接访问对象的成员变量D. 对象可以直接访问类的静态成员变量答案:A5. 下列哪些操作符属于位运算符?A. &B. +C. ||D. ~E. ^答案:ADE6. 下列哪些语句可以用来创建一个新的数组对象?A. int[] nums = {1,2,3};B. int[] nums = new int[5];C. int[] nums = new int[]{1,2,3};D. int[] nums = {};答案:BC7. 下列哪些方法属于Object类?A. toString()B. equals()C. clone()D. finalize()E. hashCode()答案:ABCDE8. 下列哪些异常是编译时异常?A. NullPointerExceptionB. FileNotFoundExceptionC. IOExceptionD. RuntimeException答案:BC9. 下列哪些集合类是线程安全的?A. ArrayListB. HashSetC. HashtableD. ConcurrentHashMap答案:C和D10. 下列哪些流是字符流?A. FileInputStreamB. FileReaderC. ObjectOutputStreamD. BufferedWriterE. ByteArrayInputStream答案:BE。
50道javase练习题(50道javase练习题).docx
50道javase练习题(50道javase练习题)[program 1]Title: classical question: there are a pair of rabbits, born from third months after birth each month a pair of rabbits, smallrabbits grow up to third months later, every month and a pair of rabbits, if the rabbit does not die,What is the total number of rabbits per month?1. program analysis: the number of rabbits・1, 1, 2, 3, 5, & 13, 21 …[program 2]Topic: determine the number of primes between 101-200, and the output of all prime numbers・1. program analysis: the method of judging prime numbers: remove 2 to sqrt (a number) with a number, if divisible,It indicates that this number is not prime, and is a prime number・[program 3]Title: print out all the "Narcissus numbers", so called ''narcissus number" refers to a three digit number, the number of cubic and equal to the number itself. For example, "153〃is a narcissus number ,Because three times three times three times 5+3 153=1.1. program analysis: use the for cycle to control 100-999 numbers, each number decomposes a bit, ten bits, hundreds・[program 4]Title: a positive integer decomposition of the quality factor・ For example: enter 90, print out 90=2*3*3*5・Program analysis: to decompose the prime factor of N, we shouldfirst find a minimum prime number k, and then complete thefollowing steps:(1)if the prime number is equal to N, the process of decomposing the prime factor is finished and printed out.(2)if n < > k, but n is divisible by K, the value of K should be printed, and divided by N K, a positive integer as a new n you repeat the first step・(3)if n is not divisible by K, with k+1 as the value of K, repeat the first step・[program 5]Title: use the nesting of conditional operators to complete this question: students with academic scores > =90 points are represented by A, 60-89 points are represented by B, and 60 points are represented by C・1. program analysis: (a> b) a:b? This is a basic example of the conditional operator・[program 6]Enter two positive integers m and N, find the greatest common divisor and least common multiple・1. program analysis: using rolling method・[program 7]Title: enter a line of characters, respectively, the number of English letters, spaces, numbets and other characters・1. program analysis: using the while statement, for the input character is not,\n.[program 8]Topic: s=a+aa+aaa+aaaa+aa・・・ A, where a is a number・ For example, 2+22+222+2222+22222 (the total sum of 5 numbers), a few numbers with keyboard contro1.1. program analysis: the key is to calculate each item value・[program 9]Topic: if a number is exactly equal to the sum of its factors, this number is called "end of a few〃. For example 6=123・ programming to find all completed within 1000.[program 10.Topic: a ball from a free fall height of 100 meters, each landing half anti jump back to the original height; then fall, for it inthe tenth floor, how many meters? How high is the rebound for the tenth time?[program 11_Title: 1, 2, 3, 4 numbers, how many different numbers can be formed without each other and three digits? How much are they?1. program analysis: can fill at 100, ten, a nu mb er is 1, 2, 3, 4. Then remove the arrangement does not meet the condition whichall arranged・[program 12_Title: corporate bonuses based on profits・ Profit (I) less than or equal to 10 million yuan, the bonus can be 10%; profit higher than 10 million, less than 20 million, less than 10 million part of the 10% Commission, higher than 10 million, cocoa percentage betwee n 20 million to 7. 5%; 40 million, 20 mill ion higher than the part the Coinmission, 5%; 40 million higher than the part between 40 million to 60 million, to the Commission of 3%;between 60 million to 100 million, higher than 60 million, to the Commission of 1.5%, higher than 100 million,More than 1 million yuan part of the Commission by 1%, from the keyboard input month profit I, the total amount of bonus shouldbe awarded?1. program analysis: please use a few axes to boundaries, positioning. Note that the definition needs to define integer growth bonus・[program 13.Title: an integer, plus 100, is a perfect square number, plus 168is a complete square number, what is the number?1. program analysis: judgment in less than 100 thousand, the number of the first and 100 after the root, then the number of plus 268 after prescribing, if after prescribing results meet the following conditions, which is the result of. Please see the concrete analysis:[program 14.Enter a certain period of a day, judgment day is the first few days this year?1. program analysis: in March 5th, for example, should first add up the first two months, and then add 5 days, that is, the first few days of the year, special circumstances, leap year and input month is greater than 3, need to consider more than one day.[program 15.Enter three integers x, y, Z, please put the three number of small to large output.1. program analysis: we try to get the smallest number on X, thefirst X compared with the Y, if x> y will X and Y values of exchange, and then x and Z are compared, if x> Z will X and Z values of exchange, so that the minimum X.[program 16_Topic: the output of 9*9 formulas・1. program analysis: branches and are considered a total of 9 rows 9, I control line, J contro1.[program 17_The monkey eats the peach problem: the monkey takes off several peaches on the first day, eats half immediately, is not addicted, eats one more second, in the morning, will eat the peach remaining half, has eaten one more・ After every morning to eat the rest of the day before a Yibanlingyi. The tenth day in the morning to eat, see only a peach・ How much did you pick up for the first day?・1. program analysis: adopt the method of reverse thinking, forward inference from・[program 18_Title: two table tennis team competition, each person three・ A team of a, B, C three, B teams for the X, y, Z three・ The list of matches has been drawn. Someone asks the players for a list of the matches・ A said he is not more than x, C said he did not x, Z, programmed to identify a list of three teams racing・1. program analysis: judge the prime number method: use a number to remove 2 to sqrt (this number), if can be divisible, it shows that this number is not prime, and vice versa is prime number・[program 19_Title: print the following pattern (diamond)** * *TiananmenResultTiananmen* * **1. program analysis: first, the graphics are divided into two parts to see, the first four lines of a rule, the latter three lines of a rule, the use of double for cycle, the first layer control line, the second layer control column.There is a sequence of fractions: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13・・・ And the sum of the first 20 of the series.1. program analysis: please seize the change rule between the numerator・[program 21_Title: 1+2! +3! + (20)1. program analysis: this procedure is to bring the cumulative become a multiplicative・[program 22]Topic: using recursive method to find 5!・1. program analysis: recursive formula: fn二fn_1*4![program 23]Topic: there are 5 people sit together, ask the fifth person how old? He said he was 2 years older than fourth・ Ask fourth people age, he said that more than third people in 2 years・ Ask third people, more than second people and two. Ask second people, two years older than the first person said・ Finally asked the first man, he said, 10 years old. How big are fifth people?1. program analysis: using the recursive method, recursive andrecursive backstepping is divided into two stages・ If you want to know the age of fifth people, you need to know the age of the fourth person, and in turn, push to the first person (10 years old), and then push back・[program 24]Title: give a no more than 5 positive integers, requirements: first, ask it is a few digits, two, reverse print out your figures ・[program 25]Title: a 5 digit, it is not a palindrome judgment・ That 12321 is a palindrome, a bit and bit the same ten million, with thousands of the same・[program 26]Title: enter the first letter of the week to determine what day it is. If the first letter is the same, then continue to judge the second letter・1. program analysis: using the situation statement is better, if the first letter is the same, then judge to use the situation statement or if sentence to determine the second letters・[program 27.Title: seeking primes within 100Title: sorting 10 numbers1. program analysis: can use the selection method, from 9 months after the comparison process, select a minimum exchange with the first element, the next analogy, with second elements and 8 Comparison and exchange・[program 29]Topic: find a 3*3 matrix and diagonal elements1. program analysis: use double for cycle control input two-dimensional array, and then accumulate a[i][i] output・[program 30.Topic: a sorted array. Now enter a number, according to the requirements of the original law it is inserted into the array.1. program analysis: first determine whether the number is greater than the last number, and then consider the insertion of the number of the middle, after inserting the element after the number, followed by a position・[program 31_Title: output an array in reverse order・ 1. program analysis: the first and the last exchange.Topic: take an integer a from the right end of the beginning of the 4 ~ 7.Program analysis: this can be considered:(1)move a to 4 bit first・(2)to set up a low of 4 for 1, the rest of the number 0. Available 〜(〜0 < <4)(3)carry on the above two operations・[program 33.Title: print Yang Hui triangle (print out 10 lines as shown below)1. program analysis:One111211464115101051 [program 34]Topic: enter the number 3 A, B, C, according to the sequence of output・1. program analysis: using pointer method・[program 35]The input array, the largest exchange with the first element, the smallest with the last element exchange, output array.[program 36_Title: there are n integers, so that the number of the front ofthe move back to m position, and finally m number into the frontof the number of M[program 37.Topic: n personal circle, order arranging・ Started from the first report (from 1 to 3 report), who reported 3 people out of the circle, leaving the last question is the original number・[program 38_Title: write a function, find the length of a string, enter the string in the main function, and output its length・Title: write a function, input n even number, call the function for 1/2+1/4+・・・ +l/n, when the input n is odd, call the function 1/1+1/3+・・・ +l/n (using pointer function)[program 40.String sorting・[program 41_The beach there is a pile of peaches, five monkeys to. The first monkey divided the peaches into five parts, one more・ The monkey threw one of the many into the sea and took one・The second monkeys divided the remaining peaches into five equally, and another one, which threw one more into the sea, took one, and third, fourth, and fifth monkeys did the same,Ask the original on the beach at least how many peaches?[program 42]Topic: 809*??二800*?? +9*?? +1?? the two digit,8*?? the result is two digits, 9*?? the result is 3 digits・ Askfor?? the double digits, and the result of 809*??.Topic: for the odd number of 0 to 7 can.[program 44.Topic: an even number can always be expressed as the sum of two primes・[program 45_Topic: whether a prime number can be divisible by 9[program 46_Title: two string connection program[program 47.Title: read the integer number of 7 numbers (1 - 50), read a value every time, and print out the number of the value・[program 48]Topic: using a public telephone transmission of data, the data is four integers, in the transmission process is encrypted, encryption rules are as follows: Each figures with 5, and then divided by 10 to replace the remainder of the digital, the first and fourth exchange, second and third exchange.Topic: Calculation of string neutron [program 50_Topic: there are five students, each student has 3 classes of results, more than from the keyboard input data (including student number, name, three course results), calculate the average score, the status of the original data and calculated the average score is stored in the disk file "stud〃・Some of them are C language questions, but they should be done with JAVA1. coding to achieve the inheritance of electrical relations: [use Javadoc annotation class, all methods, ]1 electrical appliances class (Wiring) has attributes: power (power), rated voltage (pressure),Rated current (current) and DC type (electricity)・ Method: default construction method (initialization voltage value is 220V, AC and DC type is 〃AC〃),The electrical method (work), the preparation of get and set method 1 TV for each attribute (TV) attribute: TV type (type), the maximum volume (volume) method has: construction method (current working voltage 100V, 50 TV, TV type initialization rainbow 50 inch LCD, maximum volume, 200) TV work method (work) _TV output all the attributes in the work of the value, write get and set L for the TV refrigerator Category attribute (Icebox) attribute: Volume (capacity) method with voltage method [achieve initialization refrigerator 110V, current 53,capacity of working methods 230.5] refrigerator (work) [attribute],refrigerator get prepared with set method the value of output all attributes in the work of the refrigerator; Through inheritance to achieve the above requirements, and prepare the test class WiringTest test・2. encoding is realized using Employee and Programmer two entities to illustrate the inheritance of a company.L Employee has the name and academic field attributes, and needs to provide methods to implement and display the values of these attributes・Programmer classes have attributes that represent their skill sets, which indicate the progra.mmer,s expertise in programming languages, operating systems, and databases・Similarly, need to provide a method to receive and display the values of these properties・[]analysis showed that the Employee class is a base class, which contains the name and qualification members and twoTwo methods for receiving and displaying information (acceptDetails () and displayDetails ())・ Derived classes called Programmer inelude -languages, _os, and _database3 members and two methods for receiving (acceptSkillSet ()) and displaying information (displaySkillSet ())・ Creates an object for the Programmer class, and call the base class and derived classesMethod to store and retrieve values. L modifies the above program to derive a new class from Programmer class derivation toJavaProgrammer, and the value of each member variable of the new class passes the corresponding constructorIncoming reception・Call the appropriate method to display the information・ [analysis suggests that the new class of]JavaProgrammer derives from the Programmer class and contains experience and projects data members as wellDisplayJvPrgDetails () method. Create a JavaProgrammer class object, and complete the assignment by all members of it.。
精选JAVASE综合完整版考核题库188题(含参考答案)
class Base {
public Base() throws IOException {
throw new IOException();
}
}"
答案:
A.代码编译失败,因为非抽象类不能被扩展为抽象类
B.代码编译失败,因为必须提供一个可以抛出或可以不抛出IOException异常的构造器
System.out.println(""Inside Catch"");
}
System.out.println(""At the End"");
}
}"
答案:
A.代码编译失败,因为无异常抛出
B.代码编译失败,因为未导入IOException异常类
C."输出Before Try
At the End"
D."输出Inside Catch
B.只有当catch语句未获得执行时,finally语句才获得执行
C.如果有finally语句,return语句将在finally语句执行完毕后才会返回
D.只有当异常抛出时,finally语句才获得执行
4."关于以下代码,说法正确的是?
class Example{
public static void main(String[] args) throws IOException {
test();
System.out.println(""Message1"");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(""Message2"");
精选最新版JAVASE综合测试题库188题(含答案)
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."现有如下代码:public class Example {public static void main(String[] args) {try {System.out.println(""before"");doRisyThing();System.out.println(""after"");} catch (Exception e) {System.out.println(""catch"");}System.out.println(""done"");}public static void doRisyThing() throws Exception{//this code returns unless it throws an Exception}}该代码可能的执行结果有哪些?"答案:A.before catchB.before after doneC.before catch doneD.before after catch2.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前3."请问以下代码的直接执行结果是?class Example{public static void main(String[] args) {try {System.out.println(args[0]);System.out.println(""I'm nomal"");if (true)return;} catch (Exception ex) {System.out.println(""I'm exception"");if (true)return;} finally {System.out.println(""I'm finally."");}System.out.println(""Out of try."");}}"答案:AA."I'm exceptionI'm finally."B.代码不能编译通过,因为最后一条语句位于return后,不可到达C.代码编译通过,但运行时输出异常信息D."I'm nomalI'm finally."4.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws5."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {try {throw new Exception();} catch (Exception e) {try {throw new Exception();} catch (Exception e2) {System.out.println(""inner"");}System.out.println(""middle"");}System.out.println(""out"");}"答案:DA.inner outerB.middle outerC.inner middle outerD.编译失败6."现有如下代码:public class Example {public static void main(String[] args) {// anew Example().topGo();}void topGo() {// bmiddleGo();}void middleGo() {// cgo();System.out.println(""late middle"");}void go() {// dthrow new Exception();}}为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?" 答案:BA.dB.c和dC.b、c和dD.a、b、c和d7."下面代码的执行结果是?class Example extends Utils {public static void main(String[] args) {try {System.out.print(new Example().getlnt(""42""));} catch (Exception e) {System.out.println(""Exc"");}}int getlnt(String arg) throws Exception {return Integer.parseInt(arg);}}class Utils {int getlnt() {return 42;}}"答案:BA.NFExcB.42C.42NFExcD.编译失败8.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行9."关于以下代码,说法正确的是?class Example {public static void main(String[] args) throws IOException {System.out.println(""Before Try"");try {} catch (java.io.IOException e) {System.out.println(""Inside Catch"");}System.out.println(""At the End"");}}"答案:A.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C."输出Before TryAt the End"D."输出Inside CatchAt the End"10."给出以下代码:class Example {public static void main(String[] args) throws IOException {try {methodA();} catch (IOException e) {System.out.println(""caught IOException"");}catch (Exception e) {System.out.println(""caught Exception"");}}}如果methodA()方法抛出一个IOException异常,则该程序的运行结果是什么?"答案:A.无内容输出B.代码编译失败C.输出caught IOExceptionD.输出caught Exception11.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set12."以下代码执行结果是?public abstract class Example extends Base {public abstract void method();}class Base {public Base() throws IOException {throw new IOException();}}"答案:A.代码编译失败,因为非抽象类不能被扩展为抽象类B.代码编译失败,因为必须提供一个可以抛出或可以不抛出IOException异常的构造器C.代码编译失败,以in为必须提供一个可以抛出IOException异常或其子类的构造器D.代码编译成功13.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有14.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常15.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()16.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.0317."以下代码的输出结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.round(Float.MAX_V ALUE));}}"答案:BA.输出Integer.MAX_V ALUEB.输出一个最接近Float.MAX_V ALUE的整数C.编译失败D.运行时输出异常信息18."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息19."给出以下代码,为了结果输出-12.0,方法method(d)应为以下哪个方法?public class Example {public static void main(String[] args) {double d = -11.1;double d1 = method(d);System.out.println(d1);}}"答案: AA.floor()B.ceil()C.round()D.abs()20."给出以下代码,请问在程序的第6行插入那条语句,改程序可依次打印输出11、10、9?1.public class Example {2. public static void main(String[] args) {3. double x[] = { 10.2, 9.1, 8.7 };4. int i[] = new int[3];5. for (int a = 0; a < x.length; a++) {6.7. System.out.println(i[a]);8. }9. }10.}"答案:CA.i[1] = ((int)Math.min(x[a]));B.i[1] = ((int)Math.max(x[a]));C.i[1] = ((int)Math.ceil(x[a]));D.i[1] = ((int)Math.floor(x[a]));21."以下代码执行结果是?public class Example {public static void main(String[] args) {System.out.println(Math.min(Float.NaN, Float.POSITIVE_INFINITY)); }}"答案:AA.输出NaNB.打印输出InfinityC.运行时异常,因为NaN不是有效的参数D.运行时异常,因为Infinity不是有效的参数22.关于集合中对象的equals()和hashCode()规定说法错误的是?答案:CA.如果两个对象相同,那么他们的hashCode值需要一致B.如果两个对象的hashCode值一致,他们的equals方法不一定返回trueC.equals方法默认和==判定一致D.Java中hashCode就是对象的内存地址23."给出以下代码,执行结果是?class Example {public static void main(String[] args) throws IOException {aMethod();}static void aMethod(){try {System.out.println(""Try"");return;} catch (Exception e) {System.out.println(""Catch"");}finally{System.out.println(""Finally"");}}}"答案:A.代码编译成功,但运行期间抛出异常B.代码便以失败,因为return语句错误C.输出Try和FinallyD.输出Try24."下列代码执行后的结果是?public class Example {public static void main(String[] args) {try {System.out.println(Float.NaN == Float.NaN);System.out.println(Float.POSITIVE_INFINITY==Float.POSITIVE_INFINITY); } catch (Exception e) {System.out.println(""Exception"");}}"答案:DA.输出+G20:J20false falseB.输出ExceptionC.输出true trueD.输出false true25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26."以下代码执行结果是?class RectObject {public int x;public int y;public RectObject(int x, int y) {this.x = x;this.y = y;}@Overridepublic int hashCode() {// TODO Auto-generated method stubreturn (int)System.nanoTime();}@Overridepublic boolean equals(Object obj) {return false;}}public class Example {public static void main(String[] args) {HashSet<RectObject> set = new HashSet<RectObject>();RectObject r1 = new RectObject(3, 3);RectObject r2 = new RectObject(5, 5);RectObject r3 = new RectObject(3, 3);set.add(r1);set.add(r2);set.add(r3);set.add(r1);System.out.println(""size:"" + set.size());}}"答案:A.size:1B.size:2C.size:3D.size:427.关于接口的说法,正确的是()答案:CA.接口中的方法只能在接口的实现类中实现B.接口中可定义变量成员C.接口中不能定义常量D.以上都不对28.请选择所有的正确答案。
Java_SE考试题
Java_SE考试题Java SE阶段测试一:基本语法1.下列哪些数据类型不属于基本数据类型:(多选)ACDA. BooleanB. intC. StringD. ShortE. char2.下列哪些写法是错误的:ABCA. boolean b = (boolean)3;B. int a = (int)true;C. int a = false;D. long b = (long)3.143.写出下列程序的输出结果:int a = 10, b = 4;System.out.println(a / b);2System.out.println(a % b);2System.out.println(a = b);4System.out.println(a++);44.请写代码实现将字符串变量s转换为int型,将int型变量i转换为字符串型。
Int a = Integer.parseInt(“123”)char c = i+””;5.设计一个方法,传入整形数字,不用取余运算符“%”判断该数字是奇数还是偶数。
Int a;Scanner input =new Scanner(System.in);While(true){a=a-2; if(a==0){System.out.print(“偶数”);break;} If(a==1){System.out.println(“奇数”);break;}}6.写出下列程序的输出结果:7.int a = Integer.MAX_VALUE, b = Integer.MIN_VALUE;8.System.out.println(a + b);-19.System.out.println(a>>28);710.System.out.println(b>>28);-8System.out.println(b>>>28);8byte c = (byte) 128;System.out.println(c);-12811.写出下列程序的输出结果:public class Test {public static void main(String[] args) {int a = test(3 );System.out.println(a);}private static int test(int i) {int r = 0;try {if (i > 3) return r = i;throw new NumberFormatException();} catch (NumberFormatException e) {r = 1;return r;} catch (RuntimeException e) {r = 2;return r;} finally {r = -1;}}}结果为a= 112.写出下列程序的输出结果:int x,y;x = y = 3;x = ((y=6)>(x=6))?x++:++x;System.out.println(x);System.out.println(y);X = 7Y = 613.写出下列程序的输出结果:public class Test {public static void main(String[] args) { Object x = new Object() {public boolean equals(Object obj) { return obj.getClass().equals(this.getClass()); }};Object y = new Object() {public boolean equals(Object obj) { return obj.getClass().equals(this.getClass()); }};System.out.println(x.equals(y));}}false14.写一段最短的代码造成Java堆内存溢出。
javase笔试题
javase笔试题以下是一份简单的Java SE笔试题,供您参考:一、选择题1.Java中的基本数据类型有哪些?A. byte、short、int、long、float、double、charB. byte、short、int、long、float、double、booleanC. byte、short、int、long、float、double、StringD. byte、short、int、long、float、double、char、boolean2.在Java中,以下哪个关键字用于声明一个方法?A. methodB. functionC. procedureD. func3.下列哪个选项不是Java中的注释类型?A. 单行注释B. 多行注释C. 文档注释D. 条件注释4.下列哪个选项是正确的Java标识符?A. 123abcB. abc$123C. a_b_cD. abc-1235.Java中的访问修饰符有哪些?A. private、protected、default(package-private)、publicB. private、protected、publicC. default(package-private)、protected、publicD. private、protected、default(package-private)二、填空题1.Java中的关键字________用于声明一个类。
2.Java中的关键字________用于声明一个接口。
3.Java中的关键字________用于声明一个方法。
4.Java中的关键字________用于声明一个变量。
5.Java中的关键字________用于声明一个常量。
javase编程练习题
javase编程练习题JavaSE是指Java平台标准版(Java Standard Edition),是Java编程语言的核心,提供了开发和部署Java应用程序所需的基本功能和库。
本篇文章将为读者提供一系列的JavaSE编程练习题,帮助读者提升Java编程能力并巩固对JavaSE的理解和运用。
一、题目一:计算两个数的和编写一个Java程序,实现计算两个数的和并输出结果的功能。
输入两个数,程序将计算它们的和并输出。
示例输入:2 3示例输出:5二、题目二:判断某年是否为闰年编写一个Java程序,判断某个给定的年份是否为闰年。
根据闰年的定义,当年份能被4整除但不能被100整除,或者能被400整除时就是闰年。
示例输入:2000示例输出:2000年是闰年三、题目三:计算1到n的累加和编写一个Java程序,计算从1到给定数n之间所有数的累加和。
要求使用循环语句实现。
示例输入:5示例输出:15四、题目四:判断素数编写一个Java程序,判断给定的数是否为素数。
素数是指只能被1和自身整除的大于1的整数。
示例输入:7示例输出:7是素数五、题目五:计算圆的面积编写一个Java程序,计算给定半径为r的圆的面积。
要求使用数学公式π * r * r来计算面积,其中π取3.14。
示例输入:5示例输出:圆的面积为78.5六、题目六:字符串反转编写一个Java程序,实现将给定字符串进行反转的功能。
输入一个字符串,程序将输出反转后的字符串。
示例输入:Hello World示例输出:dlroW olleH七、题目七:求解斐波那契数列编写一个Java程序,实现求解斐波那契数列的功能。
斐波那契数列是指前两个数为1,从第三个数开始,每个数是前两个数的和。
示例输入:10示例输出:1 123 5 8 13 21 34 55通过以上七个编程练习题,读者可以巩固JavaSE的基础知识,并提升自己的编程能力。
希望读者能够认真思考和解决每一个问题,并在实践中不断提升自己的编程技巧与逻辑思维能力。
(完整版)JavaSE测试题及答案
b)class A implements B implements C
c)class A implements B,C
d)class A extends B,C
4.在Java中,使用interface声明一个接口时,以下()可以用来修饰该接口。(一项)
c)java.util.Random类的nexInt()方法返回一个0(包括)和指定值之间(不包括)之间的值
d)执行代码:System.out.println(new java.util.Random().nextInt(10)+1);输出的值不可能为10.
19.在Java中,执行以下代码,两条输出语句的值分别是()(一项)
a)FileReade
b)ObjectOutputStream
c)Serialixable
d)DataOutputStream
18.在Java中,下列选项说法不正确的是()(一项)
a)jav.util.Random类用于生成随机数
b)java.util.Random类的nextInt()方法返回一个此随机生成的整数值
a)public interface A{
private int varA =10;
void methodA();
}
b)public abstract class B {
private int varA=10;
void methodA(){};
}
c)public interfacde C{
int varA =10;
sb.append(“Java”);
System.out.println(sb.toString());
精选JAVASE综合考试题库188题(含标准答案)
C.i[1] = ((int)Math.ceil(x[a]));
D.i[1] = ((int)Math.floor(x[a]));
5."以下代码执行结果是?
public class Example {
public static void main(String[] args) {
D.Map
9.List接口的特点是哪项?
答案:C
A.不允许重复元素,元素有顺序
B.允许重复元素,元素无顺序
C.允许重复元素,元素有顺序
D.不允许重复元素,元素无顺序
10.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?
答案:B
A.ArrayList myList=new Object()
s.add(""one"");
s.add(""two"");
//插入代码处
for (String s2 : sorted) {
System.out.print(s2 + "" "");
A.输出Integer.MAX_VALUE
B.输出一个最接近Float.MAX_VALUE的整数
C.编译失败
D.运行时输出异常信息
3."以下代码的运行结果是什么?
public class Example {
public static void main(String[] args) {
System.out.println(Math.min(0.0, -0.0));
3. double x[] = { 10.2, 9.1, 8.7 };
JavaSE练习题
一、单选。
1、(1分)下列选项中,不属于Java语言特点的一项是()。
A:分布式 B:安全性 C:编译执行 D:面向对象2、(1分)下列描述中,错误的是( )。
A.Java语言的性能要比C语言差B.Java能够实现一次编写,处处运行C.Java是一种面向对象的编程语言D.Java有多线程机制3、下列不属于java语言特点的是()A.自动垃圾回收机制B.面向过程的编程语言C.跨平台特性D.去除了难理解的指针等概念4、下列不是虚拟机执行过程特点的是()A.单线程B.多线程C.动态链接D.异常处理5、(1分):下面对于面向对象程序设计说法错误的是():A.面向对象程序设计思想要明显优于面向过程设计思想;B.面向对象是Java语言的基本设计思想;C.类是Java中最核心最基本的内容;D.面向对象设计思想利用封装、继承和多态等方法来实现代码的重用,减少程序错误。
6、(2分)在一个文件里面写如下代码,则此文件的文件名应该为()。
class Student{}public class Teacher{}A: Student.java B: Student.class C: Teacher.java D: Teacher.class7、每个java的编译单元可包含多个类或界面,但是每个编译单元最多只能有()类或者界面是公共的A. 一个B.两个C.四个D.任意多个8、(2分)下列不符合对象和类的关系的是( )。
A:String和“hello” B:马和马头C:人和张三 D:飞机和飞行器9、(2分):关于类的说法错误的是:()A: 类是由关键字class来声明的;B:每个类里面都要定义一个main()方法;C:命名一个类名时首字母一般要大写;D:类是对于具有相同属性和相同行为的事物的抽象10、下列哪些在java中是不合法的标识符?()A、$userB、pointC、You&neD、_endline11、属于访问控制的关键字是()。
javase初级练习题
javase初级练习题JavaSE(Java Standard Edition)是Java平台的标准版本,是用于开发和部署桌面、服务器和嵌入式环境应用程序的基础。
在JavaSE的学习过程中,做一些练习题可以帮助巩固所学知识。
本文将给出一些JavaSE初级练习题,供读者进行练习。
1. 编写一个Java程序,输出"Hello Java!"。
```javapublic class HelloWorld {public static void main(String[] args) {System.out.println("Hello Java!");}}```2. 编写一个Java程序,接受用户输入的两个整数,然后输出它们的和。
```javaimport java.util.Scanner;public class SumOfTwoNumbers {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.print("请输入第一个整数:");int num1 = scanner.nextInt();System.out.print("请输入第二个整数:");int num2 = scanner.nextInt();int sum = num1 + num2;System.out.println("两个整数的和为:" + sum); }}```3. 编写一个Java程序,判断一个数字是否为偶数。
```javaimport java.util.Scanner;public class EvenNumber {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.print("请输入一个整数:");int num = scanner.nextInt();if (num % 2 == 0) {System.out.println("该数字是偶数。
JavaSE试题
1.JAVA语言概论1.1. 选择题1.java程序的执行过程中用到一套JDK工具,其中javac.exe指A.java语言编译器B.java字节码解释器C.java文档生成器D.java类分解器2.java的API结构中,不属于类库主要包括的核心包的是A.java包B.javaxC.javadoc包扩展包3.每个java的源文件可包含多个类,但是每个源文件最多只能有()类是公共的A.一个B.两个C.四个D.任意多个4.在当前的java实现中,每个源文件就是一个以()为后缀的文件A.javaB.classC.docD.exe1.2. 填空题1.java可以跨平台的原因是____2.JAVA系统运行时,通过______机制周期性的释放无用对象所使用的内存,完成对象的清除。
3.在JAVA语言中,将后缀名为______的源代码文件编译后形成后缀名为.class的字节码文件。
4.JAVA类库具有_____的特点,保证了软件的可移植性。
5.在编写执行JAVA程序的过程中需要用到一些工具,SUN公司为我们提供了一套JDK工具,它主要包括:javac.exe、java.exe、_____、javap.exe、jkb.exe6.在JAVA语言中,为将源代码翻译成______文件时产生的错误称为编译错误。
而将程序在运行中产生的错误称为运行错误。
7.Java Application应用程序的编写和执行分3步进行:编写源代码、编译源代码、_____。
8.每个java应用程序可以包括许多方法,但必须有且只能有一个_____方法。
9.JAVA源文件中最多只能有一个_____类,其它类的个数不限。
10.类库主要包括核心JAVA包、_____和org扩展包。
2.JAVA语言基础2.1.选择题1.下列java标识符,错误的是()A._sys_varlB.$changeer_nameD.1_file2.下列不属于基本数据类型的是()A.整数类型B.类C.符点数类型D.布尔类型3.下列属于JAVA关键词的是()A.TRUEB.mainC.floatD.NULL4.下列声明和赋值语句错误的是A.double d=3.1415;B.String str=”bye”;C.float f=6.74567D.boolean boo=true;5.java中,八进制数以______开头。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
JAVA习题一、选择题1.下列哪一种叙述是正确的()A. abstract修饰符可修饰字段、方法和类B.抽象方法的body部分必须用一对大括号{ }包住C.声明抽象方法,大括号可有可无D.声明抽象方法不可写出大括号2.如下代码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);}}输出结果是什么?A. 0B. 1C. 2D. 编译失败3.下列哪种说法是正确的()A.实例方法可直接调用超类的实例方法//私有和子类重写的方法B.实例方法可直接调用超类的类方法//私有精选文库C.实例方法可直接调用其他类的实例方法D.实例方法可直接调用本类的类方法4.如下代码:class Super {public Integer getLenght() { return new Integer(4); }}public class Sub extends Super {public Long getLenght() { return new Long(5); }public static void main(String[] args) {Super sooper = new Super();Sub sub = new Sub();System.out.println(sooper.getLenght().toString() + "," +sub.getLenght().toString() );}}输出是什么?A. 4,4B. 4,5C. 5,4D. 5,5E. 编译失败 //继承重写方法后的返回类型错误5.如下代码10. public Object m() {11. Object o = new Float(3.14F);12. Object [] oa = new Object[1];13. oa[0] = o;14. o = null;15. oa[0] = null;16. print 'return 0';17. }当Float对象在第11行被创建后, 什么时候能够被垃圾回收?A. 13行以后.B. 14行以后.C. 15行以后.D. 16行以后.6.如下代码:class Base {Base() { System.out.print("Base"); }}public class Alpha extends Base {public static void main( String[] args ) {new Alpha(); -----调用父类无参的构造方法new Base();}}结果是什么?A. BaseB. BaseBaseC. 编译失败.D. 代码运行但没有输出.E. 运行时抛出异常7.以下关于异常的说法正确的是:A. 一旦出现异常,程序运行就终止了B. 如果一个方法申明将抛出某个异常,它就必须真的抛出那个异常C. 在catch子句中匹配异常是一种精确匹配D. 可能抛出系统异常的方法是不需要申明异常的8.如下代码:public class Foo {public static void main(String[] args) {try {return;} finally {System.out.println( "Finally" );}}}输出结果是什么?A. FinallyB.编译失败C. 代码正常运行但没有任何输出.D. 运行时抛出异常9.在一个线程中Sleep(1000)方法,将使得该线程在多少时间后获得对CPU的控制(假设睡眠过程中不会有其他事件唤醒该线程)?A. 正好1000毫秒B. 1000毫秒不到C. =>1000毫秒D. 不一定10.下面的语句会产生什么样的输出?System.out.println(4&7);A.4 4二进制 0100B.5 7二进制 0111C.6 4&7二进制 0100D.7E.011.下面的程序中,temp的最终值是什么?long temp=(int)3.9; //temp=3temp%=2;A .0B .1C .2D .3E .412.下面哪个不是JAVA关键字A integer intB doubleC floatD default13.下列标识符(名字)命名原则中,正确的是( )A. 类名的首字母小写B. 变量和方法名的首写字母大写C. 接口名的首写字母小写D.常量完全大写14.类Test1定义如下:1.public class Test1{2. public float aMethod(float a,float b){ return 0;}3.4.}将以下哪种方法插入行3是不合法的。
()A、public float aMethod(float a, float b,float c){ return 0;}B、public float aMethod(float c,float d){ return 0;}//方法不能重复C、public int aMethod(int a, int b){ return 0;}D、private float aMethod(int a,int b,int c){ return 0;}15.哪个语句创建了一个数组实例?A. int[] ia = new int [15];B. float fa = new float [20];C. char[] ca = “Some String”;D. int ia [][] = {4, 5, 6} {1, 2, 3};16.以public修饰的类如:public class Car{…} 则Car( )A、可被其它程序包中的类使用B、仅能被本程序包中的类使用C、不能被任意其它类使用D、不能被其它类继承17.Java程序的执行过程中用到一套JDK工具,其中java.exe是指( )A.Java文档生成器B.Java解释器C.Java编译器D.Java类分解器18.下列关于构造方法的叙述中,错误的是( )A. Java语言规定构造方法名与类名必须相同B. Java语言规定构造方法没有返回值,但不用vold声明C. Java语言规定构造方法不可以重载D. Java语言规定构造方法只能通过new自动调用19.构造函数何时被调用( )A.类定义时B.创建对象时C.调用对象方法时D.使用对象的变量时20.break语句( )A、只中断最内层的循环B、只中断最外层的循环C、借助于标号,可以实现任何外层循环中断D、只中断某一层的循环21.Java语言中下面哪个可以用作正确的变量名称()A、3DB、nameC、extendsD、implements22.下面哪一项不是Java类访问控制关键字( )A. publicB. protectedC. thisD. Private23.在接口中以下哪条定义是正确的? ( )A. void methoda();B. public double methoda();精选文库C. public final double methoda();D. static void methoda(double d1);E. protected void methoda(double d1);//接口中的成员变量都是 public static final (默认)// 接口中的方法都是 public abstract (默认)24.下面哪个语句正确地声明一个整型的二维数组?A. int a[][] = new int[][];B. int a[10][10] = new int[][];C. int a[][] = new int[10][10];D. int [][]a = new int[10][10];E. int []a[] = new int[10][10];25.下面哪些不是java的简单数据类型?A. shortB. BooleanC. DoubleD. float26.下面哪些语句能够正确地生成5个空字符串?A.String a[]=new String[5];for(int i=0;i<5;a[i++]=“”);B.String a[]={“”,“”,“”,“”,“”};C.String a[5];D.String[5]a;E.String []a=new String[5];for(int i=0;i<5;a[i++]=null);27.下列说法错误的有()A.数组是一种对象B.数组属于一种原生类C. int number=[]={31,23,33,43,35,63}D.数组的大小可以任意改变28.不能用来修饰interface的有()A.private B.public C.protected D.static29.下列说法错误的有()精选文库A.在类方法中可用this来调用本类的类方法B.在类方法中调用本类的类方法时可直接调用C.在类方法中只能调用本类中的类方法D.在类方法中绝对不能调用实例方法30.如下代码class A {A() { }}class B extends A {}哪两个说明是正确的?A. B类的构造器应该是 public.B. B类的构造器应该是没有参数C. B类的构造器应该调用this().D. B类的构造器应该调用super().31.下列标识符不合法的有()A.new B.$Usdollars C.1234 D.car.taxi32.如下代码:public class X {public X aMethod() { return this;}}public class Y extends X {}哪两个方法能加到Y类的定义中?A. public void aMethod() {}B. private void aMethod() {}C. public void aMethod(String s) {}D. private Y aMethod() { return null; }E. public X aMethod() { return new Y(); }//继承的方法返回值不能改变33.下面哪三个描述是正确的?A. 默认构造器初始化方法变量B. 默认构造器有和它所在类相同的访问修饰词.C. 默认构造器调用其父类的无参构造器.D. 如果一个类没有无参构造器,编译器会它创建一个默认构造器.E. 只有当一个类没有任何构造器时,编译器会为它创建一个默认构造器34.哪二种声明防止方法覆盖?A、final void methoda() {}B、void final methoda() {}C、static void methoda() {}D、static final void methoda() {}E、final abstract void methoda() {}35.下列程序运行结果public class ExSuper {String name;String nick_name;public ExSuper(String s, String t) {name = s;nick_name = t;}public String toString() {return name;}}public class Example extends ExSuper{public Example(String s, String t) {super(s, t);}public String toString(){return name+" a.k.a "+nick_name;}public static void main(String[] args) { ExSuper a=new ExSuper("First","1st");ExSuper b=new Example("Second","2nd");System.out.println("a is "+a.toString());System.out.println("b is "+b.toString());}}A 编译时会出现异常。