3《JAVA语言程序设计基础教程》习题解答
《Java语言程序设计基础教程》习题解答

解答:A
17、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用______字节内存空间,这样,无论是中文字符还是英文字符,都是占用______字节内存空间。
18、设x =2 ,则表达式(x ++)/3 的值是______。
C.defaultD.private
解答:C
5、下面哪一个特性不是面向对象编程主要体现的()。
A.封装性ﻩﻩB.继承
C.多态ﻩﻩD.类
解答:C
6、 不允许作为类及类成员的访问控制符的是()。
A.publicﻩB.private
C.staticﻩﻩﻩD.protected
解答:C
7、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为()。
A.int a[][]=new int[5][5];ﻩB. int [][]b=newint[5][5];
C. int []c[]=new int[5][5];ﻩD.int [][]d=newint[5,5];
解答:D
16、关于下面的程序,正确的结论是______。
publicclassex4_7{
解答:D
3、ﻩpublic staticvoid main方法的参数描述是:()
A.Stringargs[]ﻩﻩﻩB.String[] args
C.Stringsargs[]ﻩﻩD.Stringargs
解答:A,B
4、在Java中,关于CLASSPATH环境变量的说法不正确的是:()
A.CLASSPATH一旦设置之后不可修改,但可以将目录添加到该环境变量中。
java语言程序设计基础篇 复习题答案

java语言程序设计基础篇复习题答案Java语言程序设计基础篇复习题答案Java语言是一种广泛应用于软件开发领域的高级编程语言,具有跨平台、面向对象、简单易学等特点。
在学习Java语言的过程中,复习题是一种非常有效的巩固知识的方式。
本文将为大家提供一些Java语言程序设计基础篇的复习题答案,希望能够帮助大家更好地理解和掌握Java语言。
1. 以下代码的输出结果是什么?```javapublic class Test {public static void main(String[] args) {int x = 5;int y = 10;System.out.println("x + y = " + (x + y));System.out.println("x - y = " + (x - y));System.out.println("x * y = " + (x * y));System.out.println("x / y = " + (x / y));}}```答案:```x + y = 15x - y = -5x * y = 50x / y = 0```2. 以下代码的输出结果是什么?```javapublic class Test {public static void main(String[] args) { int x = 5;int y = 10;boolean result = (x > y) && (x != y); System.out.println(result);}}```答案:```false```3. 以下代码的输出结果是什么?```javapublic class Test {public static void main(String[] args) {int x = 5;int y = 10;boolean result = (x < y) || (x == y);System.out.println(result);}}```答案:```true```4. 以下代码的输出结果是什么?```javapublic class Test {public static void main(String[] args) {int x = 5;int y = 10;if (x > y) {System.out.println("x is greater than y"); } else if (x < y) {System.out.println("x is less than y");} else {System.out.println("x is equal to y");}}}```答案:```x is less than y```5. 以下代码的输出结果是什么?```javapublic class Test {public static void main(String[] args) {int x = 5;int y = 10;int max = (x > y) ? x : y;System.out.println("The maximum value is: " + max); }}```答案:```The maximum value is: 10```通过以上复习题的答案,我们可以看到Java语言程序设计基础篇中的一些基本概念和语法。
java语言程序设计基础篇复习题答案

java语言程序设计基础篇复习题答案Java语言程序设计基础篇复习题答案一、选择题1. Java是一种( A )。
A. 面向对象的编程语言B. 过程式编程语言C. 汇编语言D. 标记语言2. Java程序的执行流程是( B )。
A. 编译 -> 链接 -> 执行B. 编译 -> 运行C. 链接 -> 编译 -> 执行D. 执行 -> 编译 -> 链接3. 下列哪个是Java的关键字( D )。
A. ObjectB. StringC. IntegerD. class4. Java语言中,哪个是合法的类名( A )。
A. MyClassB. 2classC. my-classD. class5. 在Java中,哪个是正确的主方法声明( C )。
A. public void main(String args[])B. public void main(String[] args)C. public static void main(String[] args)D. static public void main(String args[])6. 下列哪个是Java的基本数据类型( C )。
A. StringB. IntegerC. intD. Object7. Java中,哪个操作符用于连接字符串( B )。
A. +B. +C. +=D. append()8. 以下哪个是Java的控制流语句( D )。
A. forB. whileC. ifD. 所有选项都是9. Java中,哪个是正确的数组声明( A )。
A. int[] numbers;B. int numbers[];C. numbers[] int;D. int numbers[]10. 在Java中,哪个是正确的方法定义( B )。
A. int add(int a, int b) { return a + b; }B. public int add(int a, int b) { return a + b; }C. private int add(int a, int b) { return a + b; }D. static int add(int a, int b) { return a + b; }二、简答题1. 简述Java语言的特点。
java语言程序设计基础篇复习题答案

java语言程序设计基础篇复习题答案一、选择题1. Java语言属于以下哪种类型的编程语言?A. 编译型语言B. 解释型语言C. 汇编语言D. 机器语言答案:B2. 下面哪个是Java语言的正确数据类型?A. intB. floatC. doubleD. 所有选项都是答案:D3. Java程序的入口点是哪一个方法?A. main()B. start()C. run()D. execute()答案:A4. Java中,哪个关键字用于定义类?A. classB. typeC. defineD. struct答案:A5. Java中的异常处理是通过什么机制实现的?A. 继承B. 多态C. 接口D. 异常处理语句答案:D二、填空题1. Java语言是一种_________语言,它支持_________和_________。
答案:面向对象;封装;继承2. 在Java中,所有的类都是从_________类继承而来的。
答案:Object3. Java程序的执行流程是从_________方法开始的。
答案:main4. Java中的数组是_________的。
答案:固定长度5. Java语言支持_________和_________两种类型的异常。
答案:编译时异常;运行时异常三、简答题1. 请简述Java语言的特点。
答案:Java语言是一种面向对象的编程语言,具有跨平台性、安全性高、健壮性、多线程等特点。
2. 请解释Java中的“垃圾回收”机制。
答案:Java的垃圾回收机制是一种自动内存管理技术,它能够自动回收不再使用的对象所占用的内存,防止内存泄漏。
四、编程题1. 编写一个Java程序,实现计算两个整数的和。
```javapublic class SumCalculator {public static void main(String[] args) {int num1 = 5;int num2 = 10;int sum = num1 + num2;System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum);}}```2. 编写一个Java程序,实现打印一个字符串的所有字符。
java基础教程第3版习题解答

Java基础教程第3版习题解答第一章习题1. JamesGoslin g2.需3个步骤:1)用文本编辑器编写源文件2)使用java c编译源文件,得到字节码文件3)应用程序使用解释器运行。
3. path d:\jdk\binclassp ath =d:\jdk\jre\lib\rt.jar;.;4. B5. java 和class6.D。
第二章习题1.用来标识类名、变量名、方法名、类型名、数组名、文件名的有效字符序列称为标识符。
标识符由字母、下划线、美元符号和数字组成,第一个字符不能是数字。
fal se不是标识符。
2.关键字就是Java语言中已经被赋予特定意义的一些单词,不可以把关键字作为名字来用。
不是关键字。
cl assi mplem entsi nterface enum extend s abstra ct。
3.float常量必须用F或f为后缀。
double常量用D或d为后缀,但允许省略后缀。
4.一维数组名.length。
二维数组名.l ength。
5. C6.ADF7. B8 【代码2】【代码3】【代码4】9.B。
10.属于操作题,解答略。
11.3,112.public classE {public static void main(String args[]) {System.out.printl n((int)'你');System.out.printl n((int)'我');System.out.printl n((int)'他');}}13.public classE {public static void main (String args[ ]) {char cStart='α',cEnd='ω';for(char c=cStart;c<=cEnd;c++)System.out.print(" "+c);}}第三章习题1. 1102.beep!!3.public classE {public static void main (String args[ ]) {for(charc='а';c<='я';c++){S ystem.out.print(" "+c);}}}4.public class Xiti3_4{ public s tatic void main(String args[]) { double sum=0,a=1;int i=1;while(i<=20){ sum=sum+a;i++;a=a*i;}System.out.println("sum="+sum);}}5.public classXiti5{ public static void main(String args[]){ int i,j;for(j=2;j<=100;j++){ for(i=2;i<=j/2;i++){ if(j%i==0)break;}if(i>j/2){ System.out.print(" "+j);}}}}6.class Xiti6{ public s tatic void main(String args[]){ double sum=0,a=1,i=1;do { sum=sum+a;i++;a=(1.0/i)*a;}while(i<=20);System.out.println("使用do-while循环计算的s um="+sum);for(sum=0,i=1,a=1;i<=20;i++){ a=a*(1.0/i);sum=sum+a;}System.out.println("使用for循环计算的s um="+sum);}}7.class Xiti7{ public s tatic void main(String args[]){ int sum=0,i,j;for(i=1;i<=1000;i++){ for(j=1,sum=0;j<i;j++){ if(i%j==0)sum=sum+j;}if(sum==i)System.out.println("完数:"+i);}}}8.import java.util.*;public classE {public static void main (String args[ ]) {int m,n;Scanne r scaner= new Scanne r(System.in);System.out.println("输入正数m回车确认");m = scaner.nextIn t();System.out.println("输入正数n回车确认");n = scaner.nextIn t();int p=m;int q= n;int r = m%n;while(r!=0) {m = n;n =r;r =m%n;}System.out.println(p+"和"+q+"的最大公约数"+n);System.out.println(p+"和"+q+"的最小公倍数"+(p*q)/n);}}9.public classE{ public static void main(String args[]){ int n=1;long sum=0;while(true){ sum=sum+n;n++;if(sum>=8888)break;}System.out.println("满足条件的最大整数:"+(n-1));}}第四章习题1.用该类创建对象时。
《Java语言程序设计教程》习题参考答案

参考源代码如下:
import java.io.*;
public class Programming0401
{ public static void main(String []args)
{ int a=5,b=10,c;
x2=Integer.parseInt(rr.readLine());
}
catch(IOException e){ }
fx1=x1*((2*x1-4)*x1+3)-6;
fx2=x2*((2*x2-4)*x2+3)-6;
}while(fx1*fx2>0);
do
{x0=(x1+x2)/2;
fx0=x0*((2*x0-4)*x0+3)-6;
7.关系8.switch9.Break10.多层循环
三、编程题
1.用二分法求方程2x3–4x2+3x–6=0在(–10,10)之间的根。
参考源代码如下:
import java.io.*;
public class Programming0501
{ public static void main(String args[])
a[i][j]=(int)(Math.random()*100+10);
System.out.println("矩阵A的各个元素为:");
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
System.out.print(a[i][j]+" ");
Java语言程序设计课后习题答案全集

Java语言程序设计课后习题答案全集Java语言程序设计是一门广泛应用于软件开发领域的编程语言,随着其应用范围的不断扩大,对于掌握Java编程技巧的需求也逐渐增加。
为了帮助读者更好地掌握Java编程,本文将提供Java语言程序设计课后习题的全集答案,供读者参考。
一、基础知识题1. 代码中的注释是什么作用?如何使用注释.答:注释在代码中是用来解释或者说明代码的功能或用途的语句,编译器在编译代码时会自动忽略注释。
在Java中,有三种注释的方式:- 单行注释:使用"// " 可以在代码的一行中加入注释。
- 多行注释:使用"/* */" 可以在多行中添加注释。
- 文档注释:使用"/** */" 可以添加方法或类的文档注释。
2. 什么是Java的数据类型?请列举常见的数据类型。
答:Java的数据类型用来指定变量的类型,常见的数据类型有:- 基本数据类型:包括整型(byte、short、int、long)、浮点型(float、double)、字符型(char)、布尔型(boolean)。
- 引用数据类型:包括类(class)、接口(interface)、数组(array)等。
二、代码编写题1. 编写Java程序,输入两个整数,求和并输出结果。
答:```javaimport java.util.Scanner;public class SumCalculator {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);}}```三、综合应用题1. 编写Java程序,实现学生信息管理系统,要求包括以下功能:- 添加学生信息(姓名、年龄、性别、学号等);- 修改学生信息;- 删除学生信息;- 查询学生信息。
java语言程序设计基础篇复习题答案

java语言程序设计基础篇复习题答案# Java语言程序设计基础篇复习题答案一、选择题1. Java是一种面向对象的编程语言,它是由SUN公司开发的。
(对)2. Java程序的源文件扩展名是.java,编译后的文件扩展名是.class。
(对)3. Java语言是编译型语言,不是解释型语言。
(错)4. Java语言的跨平台特性主要得益于Java虚拟机(JVM)。
(对)5. 在Java中,可以通过`==`操作符来比较两个字符串的内容是否相等。
(错)二、填空题1. Java语言的基本数据类型包括:byte、short、int、long、float、double、char、boolean。
2. Java中用`public class`定义类时,类名必须与文件名相同。
3. Java程序的入口方法是`main`方法,它必须声明为`public static void main(String[] args)`。
4. Java中,`new`关键字用于创建对象。
5. 访问控制修饰符包括:public、private、protected、default(无修饰符)。
三、简答题1. 简述Java语言的特点。
- Java是一种面向对象的编程语言,具有封装、继承和多态性。
- Java是平台无关的,可以在任何安装了Java虚拟机的设备上运行。
- Java具有强类型检查,提高了代码的安全性和可读性。
- Java提供了丰富的标准库,方便开发者快速开发。
2. 解释Java中的异常处理机制。
- Java使用try-catch-finally块来处理异常。
- try块包含可能会抛出异常的代码。
- catch块用于捕获并处理异常。
- finally块中的代码无论是否发生异常都会执行,常用于资源的清理。
3. 描述Java中集合框架的基本概念。
- Java集合框架是一组相关的接口和类,用于存储和处理对象集合。
- 基本接口包括:Collection、List、Set、Map。
Java程序设计基础习题答案

Java程序设计基础课后习题参考答案第2章1. 关于Java Application 的入口方法main()的检验:main()方法的参数名是否可以改变?main()方法的参数个数是否可以改变?该方法名是否可以改变?参考答案:(1)main()方法的参数名可以改变。
(2)main()方法的参数个数不可以改变。
(3)该方法名不可以改变。
2. 当一个程序没有main()方法时,能编译吗?如果能编译,能运行吗?参考答案:当一个程序没有main()方法是,是可以编译通过的,但是不能给运行,因为找不到一个主函数入口。
3. 下列语句能否编译通过?byte i = 127;byte j = 128;long l1 = 999999;long l2 = 9999999999;参考答案:byte i 和long l1可以编译通过。
而byte j 和long l2 超出自身数据类型范围,所以编译失败。
4. 下列语句能否编译通过?float f1 = 3.5;float f2 = 3.5f;参考答案:java中浮点型的数据在不声明的情况下都是double型的,如果要表示一个数据是float型的,必须在数据后面加上“F”或“f”;因此,float f1 无法编译通过。
5. 验证int 和char,int和double等类型是否可以相互转换。
参考答案:(1)char类型可以转换为int 类型的,但是int类型无法转换为char类型的;(2)int 可以转换为double类型的,但是double类型无法转换为int 类型的。
6. 计算下列表达式,注意观察运算符优先级规则。
若有表达式是非法表达式,则指出不合法之处且进行解释。
(1) 4+5 == 6*2 (2) (4=5)/6(3) 9%2*7/3>17 (4) (4+5)<=6/3(5) 4+5%3!=7-2 (6) 4+5/6>=10%2参考答案:表达式(2)为不合法表达式,只能将值赋值给一个变量,因此其中(4=5)将5赋值给4是不合法的。
JAVA语言程序设计(基础篇)答案

3.4import javax.swing.*;public class AdditionTutor{public static void main(String[] args){int number1=(int)(System.currentTimeMillis()%100);int number2=(int)(System.currentTimeMillis()*5%100);String answerString=JOptionPane.showInputDialog("what is "+ number1 +"+ "+ number2+" ?");int answer=Integer.parseInt(answerString);JOptionPane.showMessageDialog(null,number1 +" + "+ number2 +" = "+answer+" is "+(number1+number2==answer));}}3.10import javax.swing.JOptionPane;public class ComputeTaxWithSelectionStatement{public static void main(String[] args){//Prompt the user to enter filing statusString statusString = JOptionPane.showInputDialog("Enter the filing status:\n"+"(0-single filer,1-married jointly,\n"+"2-married separately,3-head of household)");int status = Integer.parseInt(statusString);//Prompt the user to enter taxable incomeString incomeString = JOptionPane.showInputDialog("Enter the taxable income:");double income = Double.parseDouble(incomeString);//Comput taxdouble tax=0;if (status == 0){//Compute tax for single filersif (income <= 6000)tax = income * 0.10;else if (income <= 27950)tax = 6000 * 0.10 + (income - 6000) * 0.15;else if (income <= 67700)tax = 6000 * 0.10 + (27950 - 6000) * 0.15 +(income - 27950) * 0.27;else if (income <= 141250)tax = 6000 * 0.10 + (27950 - 6000) * 0.15 +(67700 - 27950) * 0.27 + (income - 67700) * 0.30;else if (income <=307050)tax = 6000 * 0.10 + (27950 - 6000) * 0.15 +(67700 - 27950) * 0.27 + (141250 - 67700) * 0.30 +(income - 141250) * 0.35;elsetax = 6000 * 0.10 + (27950 - 6000) * 0.15 +(67700 - 27950) * 0.27 + (141250 -67700) * 0.30 +(307050 - 141250) * 0.35 + (income - 307050) * 0.386;}else if (status == 1){//Compute tax for married file jointly if (income <= 12000)tax = income * 0.10;else if (income <= 46700)tax = 12000 * 0.10 + (income - 12000) * 0.15;else if (income <= 112850)tax = 12000 * 0.10 + (46700 - 12000) * 0.15 +(income - 46700) * 0.27;else if (income <= 171950)tax = 12000 * 0.10 + (46700 - 12000) * 0.15 +(112850 - 46700) * 0.27 + (income - 112850) * 0.30;else if (income <= 307050)tax = 12000 * 0.10 + (46700 - 12000) * 0.15 +(112850 - 46700) * 0.27 + (141250 - 112850) * 0.30 +(income - 307050) * 0.35;elsetax = 12000 * 0.10 + (46700 - 12000) * 0.15 +(112850 - 46700 ) * 0.27 + (171950 - 112850) * 0.30 +(307050 - 171950) * 0.35 + (income - 307050) * 0.386;}else if (status == 2){//Compute tax for married separately if (income <= 6000)tax = income * 0.10;else if (income <= 23350)tax = 6000 * 0.10 + (income - 6000) * 0.15;else if (income <= 56425)tax = 6000 * 0.10 + (23350 - 6000) * 0.15 +(income - 23350) * 0.27;else if (income <= 85975)tax = 6000 * 0.10 + (23350 - 6000) * 0.15 +(56425 - 23350) * 0.27 + (income - 56425) * 0.30;else if (income <= 153525)tax = 6000 * 0.10 + (23350 - 6000) * 0.15 +(56425 - 23350) * 0.27 + (85975 - 56425) * 0.30 +(income - 85975) * 0.35;elsetax = 6000 * 0.10 + (23350 - 6000) * 0.15 +(56425 - 23350) * 0.27 + (85975 - 56425) * 0.30 +(153525 - 85975) * 0.35 + (income - 153525) * 0.386;}else if (status == 3){//Compute tax for head of householdif (income <= 10000)tax = income * 0.10;else if (income <= 37450)tax = 10000 * 0.10 + (income - 10000) * 0.15;else if (income <= 96700)tax = 10000 * 0.10 + (37450 - 10000) * 0.15 +(income - 37450) * 0.27;else if (income <= 156600)tax = 10000 * 0.10 + (37450 - 10000) * 0.15 +(96700 - 37450) * 0.27 + (income - 96700) * 0.30;else if (income <= 307050)tax = 10000 * 0.10 + (37450 - 10000) * 0.15 +(96700 - 37450) * 0.27 + (156600 - 96700) * 0.30 +(income - 156600) * 0.35;elsetax = 10000 * 0.10 + (37450 - 10000) * 0.15 +(96700 - 37450) * 0.27 + (156600 - 96700) * 0.30 +(307050 - 156600) * 0.35 + (income - 307050) * 0.386;}else{System.out.println("Error: invalid status");System.exit(0);}//Display the resultJOptionPane.showMessageDialog(null,"Tax is " +(int)(tax * 100) / 100.0);}}4.11public class ZhengChu{public static void main(String[] args){int count=0;for(int i=100;i<=200;i++){if((i%5==0||i%6==0)&&i%30!=0){System.out.print(" "+ i);count++;if(count%10==0)System.out.println();}}}}4.14public class ASCII{public static void main(String[] args){int count = 0;for(int i = 33; i <= 126; i++){count++;char ch = (char)i;System.out.print(" " + ch);if(count % 10 == 0)System.out.println();}}}4.17import javax.swing.JOptionPane;public class FindSalesAmount{/**Main method*/public static void main(String[] args){//The commission soughtString COMMISSION_SOUGHTString = JOptionPane.showInputDialog("Enter the COMMISSION_SOUGHT :");double COMMISSION_SOUGHT = Double.parseDouble(COMMISSION_SOUGHTString);double commission = 0;double salesAmount;for (salesAmount = 0.01;commission <= COMMISSION_SOUGHT;){salesAmount += 0.01; //防止犯off-by-one错误,先判断在做自加!if (salesAmount >= 10000.01)commission =5000 * 0.08 + 5000 * 0.1 + (salesAmount - 10000) * 0.12;else if (salesAmount >= 5000.01)commission = 5000 * 0.08 + (salesAmount - 5000) * 0.10;elsecommission = salesAmount * 0.08;}String output ="The sales amount $" + (int)(salesAmount * 100) / 100.0 +"\n is needed to make a commission of $" + COMMISSION_SOUGHT;JOptionPane.showMessageDialog(null,output);}}5.6import javax.swing.JOptionPane;public class PrintPyramid{public static void main(String[] args){String input = JOptionPane.showInputDialog("Enter the number of lines:");int numberOfLines = Integer.parseInt(input);displayPattern(numberOfLines);}public static void displayPattern(int n){for (int row = 1;row <= n;row++){for (int column = 1;column <= n - row;column++)System.out.print(" ");for (int num = row;num >= 1;num--)System.out.print((num >= 10) ? " " + num : " " + num);System.out.println();}}}5.18public class MathSuanFa{public static void main(String[] args){double A = Math.sqrt(4);double B = (int)Math.sin(2 * Math.PI);double C = (int)Math.cos(2 * Math.PI);double D = (int)Math.pow(2, 2);double E = (int)Math.log(Math.E);double F = (int)(Math.exp(1)*100000)/100000.0;double G = (int)Math.max(2, Math.min(3, 4));double H = (int)Math.rint(-2.5);double I = (int)Math.ceil(-2.5);double J = (int)Math.floor(-2.5);int K = (int)Math.round(-2.5f);int L = (int)Math.round(-2.5);double M = (int)Math.rint(2.5);double N = (int)Math.ceil(2.5);double O = (int)Math.floor(2.5);int P = (int)Math.round(2.5f);int Q = (int)Math.round(2.5);int R = (int)Math.round(Math.abs(-2.5));System.out.println(A +" "+ B +" "+ C +" "+ D +" "+ E +" "+ F +" "+ G +" "+ H +" "+ I +" "+ J +" "+ K +" "+ L +" "+ M +" "+ N +" "+ O +" "+ P +" "+ Q +" "+ R);}}6.9import javax.swing.JOptionPane;public class Array{public static void main (String[] args){String incomeString = JOptionPane.showInputDialog("Enter the number of array size:");int income = Integer.parseInt(incomeString);int arraySize = income;int [] myList = new int [arraySize];int m;for ( m = 0; m < arraySize; m++){String elementString = JOptionPane.showInputDialog("Enter the " + (m + 1) + " element of the array");int element = Integer.parseInt(elementString);myList[m] = element;}int minElement = myList[0];for (int i=1; i < arraySize; i++){if (myList[i] < minElement)minElement = myList[i];}JOptionPane.showMessageDialog(null,"The min element is: " + minElement); }}。
《Java语言程序设计-基础篇》第03章答案

《Java语言程序设计-基础篇》第03章答案3.1 答:if(i % 2 == 0) System.out.println(“偶数”); else System.out.println(“奇数”); 3.2 答:当 x = 3, y = 2 时,输出:无输出当x = 3, y = 4 时,输出:z is 7 当 x = 2,y = 2 时,输出:x is 2 3.3 答:等价的语句有:a, c和d 正确缩进的是:c 3.4 答:当 x = 2, y = 3 时,输出:x is 2 当 x = 3, y = 2 时,输出:无输出当 x = 3,y = 3 时,输出:z is 7 3.5 答:等价 3.6 答:switch变量可以是char, byte, short, int。
执行case语句后没有break,则继续执行下一个case语句。
switch可转换为等价的if语句(嵌套),反之不一定可以。
3.7 答:y的值是2。
3.8 答:switch(a){ case 1: x += 5; break; case 2: x += 10; break; case 3: x += 16; break; case 4: x += 34; } 3.9 答:System.out.print(count + (count % 10 == 0 ? “\n“ : ““)); 3.10 答:(a)执行0次,无输出(b)执行9次,输出如下:3 5 7 9 3.11 答:(略)3.12 答:相同,均为45。
3.13 答:for(int i = 1; i System.out.println(i); 3.14 答:无限循环。
3.15 答:不能。
3.16 答:能。
(略)3.17 答:(略)3.18 答:(a)输出:balance is 1 (b)不能结束(编译有错,输出语句执行不到)3.19 答:能。
(略)3.20 答:int i=0; while(iif(i%3==0){ i++; continue; } sum += i; i++; } 3.21 答:(a)主方法如下:public static void main(String[] args) { int sum = 0; int number = 0; while(number number++; sum += number; } System.out.println(“The number is “ + number); System.out.println(“The sum is “ + sum); } (b)主方法如下:public static void main(String[] args) { int sum = 0; int number = 0; while(number number++; if(!(number == 10 || number == 11)) sum += number; } System.out.println(“The number is “ + number); System.out.println(“Thesum is “ + sum); } 3.22 答:执行next:后面的语句。
java程序设计基础 课后习题答案

java程序设计基础课后习题答案Java程序设计基础课后习题答案Java程序设计是一门广泛应用于软件开发领域的编程语言。
在学习这门课程时,除了理论知识的学习外,课后习题也是非常重要的一部分。
通过课后习题的练习,可以帮助学生巩固所学的知识,并且提高编程能力。
下面将为大家提供一些Java程序设计基础课后习题的答案,希望对大家的学习有所帮助。
习题一:编写一个Java程序,输出从1到100之间所有的奇数。
```javapublic class OddNumbers {public static void main(String[] args) {for (int i = 1; i <= 100; i++) {if (i % 2 != 0) {System.out.println(i);}}}}```习题二:编写一个Java程序,计算1到100之间所有偶数的和。
```javapublic class EvenSum {public static void main(String[] args) {for (int i = 1; i <= 100; i++) {if (i % 2 == 0) {sum += i;}}System.out.println("1到100之间所有偶数的和为:" + sum); }}```习题三:编写一个Java程序,判断一个数是否为素数。
```javaimport java.util.Scanner;public class PrimeNumber {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.print("请输入一个整数:");int num = scanner.nextInt();boolean isPrime = true;for (int i = 2; i <= Math.sqrt(num); i++) {if (num % i == 0) {isPrime = false;}}if (isPrime) {System.out.println(num + "是素数");} else {System.out.println(num + "不是素数");}}}```习题四:编写一个Java程序,统计一个字符串中每个字符出现的次数。
JAVA语言程序设计(基础篇)答案

3.4import javax.swing.*;public class AdditionTutor{public static void main(String[] args){int number1=(int)(System.currentTimeMillis()%100);int number2=(int)(System.currentTimeMillis()*5%100);String answerString=JOptionPane.showInputDialog("what is "+ number1 +"+ "+ number2+" ?");int answer=Integer.parseInt(answerString);JOptionPane.showMessageDialog(null,number1 +" + "+ number2 +" = "+answer+" is "+(number1+number2==answer));}}3.10import javax.swing.JOptionPane;public class ComputeTaxWithSelectionStatement{public static void main(String[] args){//Prompt the user to enter filing statusString statusString = JOptionPane.showInputDialog("Enter the filing status:\n"+"(0-single filer,1-married jointly,\n"+"2-married separately,3-head of household)");int status = Integer.parseInt(statusString);//Prompt the user to enter taxable incomeString incomeString = JOptionPane.showInputDialog("Enter the taxable income:");double income = Double.parseDouble(incomeString);//Comput taxdouble tax=0;if (status == 0){//Compute tax for single filersif (income <= 6000)tax = income * 0.10;else if (income <= 27950)tax = 6000 * 0.10 + (income - 6000) * 0.15;else if (income <= 67700)tax = 6000 * 0.10 + (27950 - 6000) * 0.15 +(income - 27950) * 0.27;else if (income <= 141250)tax = 6000 * 0.10 + (27950 - 6000) * 0.15 +(67700 - 27950) * 0.27 + (income - 67700) * 0.30;else if (income <=307050)tax = 6000 * 0.10 + (27950 - 6000) * 0.15 +(67700 - 27950) * 0.27 + (141250 - 67700) * 0.30 +(income - 141250) * 0.35;elsetax = 6000 * 0.10 + (27950 - 6000) * 0.15 +(67700 - 27950) * 0.27 + (141250 -67700) * 0.30 +(307050 - 141250) * 0.35 + (income - 307050) * 0.386;}else if (status == 1){//Compute tax for married file jointly if (income <= 12000)tax = income * 0.10;else if (income <= 46700)tax = 12000 * 0.10 + (income - 12000) * 0.15;else if (income <= 112850)tax = 12000 * 0.10 + (46700 - 12000) * 0.15 +(income - 46700) * 0.27;else if (income <= 171950)tax = 12000 * 0.10 + (46700 - 12000) * 0.15 +(112850 - 46700) * 0.27 + (income - 112850) * 0.30;else if (income <= 307050)tax = 12000 * 0.10 + (46700 - 12000) * 0.15 +(112850 - 46700) * 0.27 + (141250 - 112850) * 0.30 +(income - 307050) * 0.35;elsetax = 12000 * 0.10 + (46700 - 12000) * 0.15 +(112850 - 46700 ) * 0.27 + (171950 - 112850) * 0.30 +(307050 - 171950) * 0.35 + (income - 307050) * 0.386;}else if (status == 2){//Compute tax for married separately if (income <= 6000)tax = income * 0.10;else if (income <= 23350)tax = 6000 * 0.10 + (income - 6000) * 0.15;else if (income <= 56425)tax = 6000 * 0.10 + (23350 - 6000) * 0.15 +(income - 23350) * 0.27;else if (income <= 85975)tax = 6000 * 0.10 + (23350 - 6000) * 0.15 +(56425 - 23350) * 0.27 + (income - 56425) * 0.30;else if (income <= 153525)tax = 6000 * 0.10 + (23350 - 6000) * 0.15 +(56425 - 23350) * 0.27 + (85975 - 56425) * 0.30 +(income - 85975) * 0.35;elsetax = 6000 * 0.10 + (23350 - 6000) * 0.15 +(56425 - 23350) * 0.27 + (85975 - 56425) * 0.30 +(153525 - 85975) * 0.35 + (income - 153525) * 0.386;}else if (status == 3){//Compute tax for head of householdif (income <= 10000)tax = income * 0.10;else if (income <= 37450)tax = 10000 * 0.10 + (income - 10000) * 0.15;else if (income <= 96700)tax = 10000 * 0.10 + (37450 - 10000) * 0.15 +(income - 37450) * 0.27;else if (income <= 156600)tax = 10000 * 0.10 + (37450 - 10000) * 0.15 +(96700 - 37450) * 0.27 + (income - 96700) * 0.30;else if (income <= 307050)tax = 10000 * 0.10 + (37450 - 10000) * 0.15 +(96700 - 37450) * 0.27 + (156600 - 96700) * 0.30 +(income - 156600) * 0.35;elsetax = 10000 * 0.10 + (37450 - 10000) * 0.15 +(96700 - 37450) * 0.27 + (156600 - 96700) * 0.30 +(307050 - 156600) * 0.35 + (income - 307050) * 0.386;}else{System.out.println("Error: invalid status");System.exit(0);}//Display the resultJOptionPane.showMessageDialog(null,"Tax is " +(int)(tax * 100) / 100.0);}}4.11public class ZhengChu{public static void main(String[] args){int count=0;for(int i=100;i<=200;i++){if((i%5==0||i%6==0)&&i%30!=0){System.out.print(" "+ i);count++;if(count%10==0)System.out.println();}}}}4.14public class ASCII{public static void main(String[] args){int count = 0;for(int i = 33; i <= 126; i++){count++;char ch = (char)i;System.out.print(" " + ch);if(count % 10 == 0)System.out.println();}}}4.17import javax.swing.JOptionPane;public class FindSalesAmount{/**Main method*/public static void main(String[] args){//The commission soughtString COMMISSION_SOUGHTString = JOptionPane.showInputDialog("Enter the COMMISSION_SOUGHT :");double COMMISSION_SOUGHT = Double.parseDouble(COMMISSION_SOUGHTString);double commission = 0;double salesAmount;for (salesAmount = 0.01;commission <= COMMISSION_SOUGHT;){salesAmount += 0.01; //防止犯off-by-one错误,先判断在做自加!if (salesAmount >= 10000.01)commission =5000 * 0.08 + 5000 * 0.1 + (salesAmount - 10000) * 0.12;else if (salesAmount >= 5000.01)commission = 5000 * 0.08 + (salesAmount - 5000) * 0.10;elsecommission = salesAmount * 0.08;}String output ="The sales amount $" + (int)(salesAmount * 100) / 100.0 +"\n is needed to make a commission of $" + COMMISSION_SOUGHT;JOptionPane.showMessageDialog(null,output);}}5.6import javax.swing.JOptionPane;public class PrintPyramid{public static void main(String[] args){String input = JOptionPane.showInputDialog("Enter the number of lines:");int numberOfLines = Integer.parseInt(input);displayPattern(numberOfLines);}public static void displayPattern(int n){for (int row = 1;row <= n;row++){for (int column = 1;column <= n - row;column++)System.out.print(" ");for (int num = row;num >= 1;num--)System.out.print((num >= 10) ? " " + num : " " + num);System.out.println();}}}5.18public class MathSuanFa{public static void main(String[] args){double A = Math.sqrt(4);double B = (int)Math.sin(2 * Math.PI);double C = (int)Math.cos(2 * Math.PI);double D = (int)Math.pow(2, 2);double E = (int)Math.log(Math.E);double F = (int)(Math.exp(1)*100000)/100000.0;double G = (int)Math.max(2, Math.min(3, 4));double H = (int)Math.rint(-2.5);double I = (int)Math.ceil(-2.5);double J = (int)Math.floor(-2.5);int K = (int)Math.round(-2.5f);int L = (int)Math.round(-2.5);double M = (int)Math.rint(2.5);double N = (int)Math.ceil(2.5);double O = (int)Math.floor(2.5);int P = (int)Math.round(2.5f);int Q = (int)Math.round(2.5);int R = (int)Math.round(Math.abs(-2.5));System.out.println(A +" "+ B +" "+ C +" "+ D +" "+ E +" "+ F +" "+ G +" "+ H +" "+ I +" "+ J +" "+ K +" "+ L +" "+ M +" "+ N +" "+ O +" "+ P +" "+ Q +" "+ R);}}6.9import javax.swing.JOptionPane;public class Array{public static void main (String[] args){String incomeString = JOptionPane.showInputDialog("Enter the number of array size:");int income = Integer.parseInt(incomeString);int arraySize = income;int [] myList = new int [arraySize];int m;for ( m = 0; m < arraySize; m++){String elementString = JOptionPane.showInputDialog("Enter the " + (m + 1) + " element of the array");int element = Integer.parseInt(elementString);myList[m] = element;}int minElement = myList[0];for (int i=1; i < arraySize; i++){if (myList[i] < minElement)minElement = myList[i];}JOptionPane.showMessageDialog(null,"The min element is: " + minElement); }}。
《Java语言程序设计基础教程》习题解答

B、25103388
C、88102335
D、53321088
解答:B
14、下列语句有错误的就是:( )
A、int []a;B、int []b=new int[10];
C、int c[]=new int[];D、int d[]=null;
解答:C
15、下列语句有错误的就是:( )
A、int a[][]=new int[5][5];B、int [][]b=new int[5][5];
int l = 0;
do {
System、out、println("Doing it for l is:" + l);
} while (--l > 0);
System、out、println("Finish");
}
}
A、Doing it for l is 3
B、Doing it for l is 1
max=x[i];
}
System、out、println(max);
A、2B、-8
C、7D、9
解答:D
12、设x = 1 , y = 2 , z = 3,则表达式y+=z--/++x的值就是( )
A、3B、3、5
C、4D、5
解答:A
13、有整型数组:int[] x={2,33,88,5,10};,则调用方法Arrays、sort(x)后,数组x中的元素值依次就是?( )
A、仅仅III
B、I与III
C、仅仅I
D、I, II与III
解答:B
5、下列整型数据类型中,需要内存空间最少的就是( )。
A、shortB、long
java语言程序设计基础篇 复习题答案

java语言程序设计基础篇复习题答案
Java语言程序设计基础篇复习题答案
在学习Java语言程序设计基础篇的过程中,复习题是一个很好的方式来巩固所学知识。
下面是一些常见问题的答案,希望能够帮助大家更好地复习和理解Java语言程序设计基础篇的知识。
1. 什么是Java语言的特点?
答:Java语言具有简单、面向对象、分布式、多线程、动态、解释性等特点。
2. Java语言有哪些基本数据类型?
答:Java语言的基本数据类型包括整型、浮点型、字符型、布尔型等。
3. 什么是Java语言中的变量?
答:变量是用来存储数据的内存空间,它具有数据类型和名称。
4. Java语言中的运算符有哪些?
答:Java语言中的运算符包括算术运算符、关系运算符、逻辑运算符、位运算符等。
5. 什么是Java语言中的控制语句?
答:控制语句用于控制程序的执行流程,包括顺序结构、选择结构、循环结构等。
6. 什么是Java语言中的数组?
答:数组是一种用来存储多个相同类型数据的数据结构。
7. Java语言中的方法是什么?
答:方法是一段用来完成特定任务的代码,它可以被重复使用。
8. 什么是Java语言中的类和对象?
答:类是一种模板,用来描述对象的属性和行为;对象是类的实例,具有特定的属性和行为。
通过复习这些问题的答案,我们可以更好地理解和掌握Java语言程序设计基础篇的知识,为以后的学习和实践打下坚实的基础。
希望大家在学习Java语言程序设计基础篇的过程中能够不断努力,取得更好的成绩。
java语言程序设计基础篇复习题答案

java语言程序设计基础篇复习题答案
Java语言程序设计基础篇复习题答案
在学习Java语言程序设计基础时,复习题是一个非常重要的环节。
通过复习题的练习,可以帮助我们巩固知识,加深对Java语言程序设计基础的理解。
下面是一些常见的Java语言程序设计基础篇复习题答案,供大家参考。
1. 什么是Java语言的特点?
答:Java语言的特点包括跨平台性、面向对象、健壮性、安全性、简单性、多线程、动态性和高性能等。
2. 什么是Java的基本数据类型?
答:Java的基本数据类型包括整型、浮点型、字符型、布尔型四种基本类型,分别为int、float、char、boolean。
3. 什么是Java的面向对象编程?
答:Java的面向对象编程是一种程序设计思想,它将现实世界中的事物抽象成对象,并通过对象之间的交互来实现程序的功能。
4. 什么是Java的类和对象?
答:Java的类是一种抽象的数据类型,它是对象的模板,用来描述对象的属性和行为。
而对象是类的实例,它具体表现了类的特征。
5. 什么是Java的封装、继承和多态?
答:Java的封装是一种将数据和行为封装在类中,隐藏内部的实现细节,只对外提供接口的机制。
继承是一种通过创建新类来扩展已有类的属性和行为的机制。
多态是一种同一操作作用于不同的对象上,可以有不同的解释和不同的实现的机制。
通过对这些复习题的回答,我们可以加深对Java语言程序设计基础的理解,为进一步的学习和实践打下坚实的基础。
希望大家在学习Java语言程序设计基础时,能够认真对待复习题,不断提升自己的编程能力。
[Java程序设计教程(第三版)课后习题答案

参考答案第1章1.Java语言有哪些主要特点?平台独立性安全性多线程网络化面向对象2.Java编程语言有哪四种不同的平台?Java 编程语言有四种平台:Java 标准版 (Java SE)、Java 企业版 (Java EE)、Java 微型版 (Java ME)和JavaFX。
所有 Java 都由 Java 虚拟机 (VM)和应用程序编程接口 (API) 组成。
Java虚拟机是一个用于特定硬件和软件平台的程序,它运行 Java 技术应用程序。
API 是一组软件组件,可用于创建其他软件组件或应用程序。
每个 Java平台都提供了一个虚拟机和一个API,这使得为该平台编写的应用程序可以在具有 Java编程语言所有优点的任何兼容系统上运行:平台独立性、功能强大、稳定性、易于开发和安全。
Java SE当大多数人想到 Java 编程语言时,他们会想到 Java SE API。
Java SE 的 API 提供了 Java 编程语言的核心功能。
它定义了从 Java编程语言的基本类型和对象到用于网络、安全、数据库访问、图形用户界面(GUI) 开发和 XML 解析的高级类的所有内容。
除了核心 API 之外,Java SE平台还包括虚拟机、开发工具、部署技术以及 Java技术应用程序中常用的其他类库和工具包。
Java EEJava EE 平台构建在 Java SE 平台之上。
Java EE平台为开发和运行大规模、多层、可扩展、可靠和安全的网络应用程序提供了API 和运行时环境。
Java MEJava ME 平台提供了一个 API和一个小型虚拟机,用于在小型设备(如手机)上运行 Java 编程语言应用程序。
该API 是 Java SE API的一个子集,以及对小型设备应用程序开发有用的特殊类库。
Java ME应用程序通常是 Java EE 平台服务的客户端。
JavaFXJavaFX 是一个使用轻量级用户界面 API 创建富 Internet应用程序的平台。
3《JAVA语言程序设计基础教程》习题解答

23、已知数组 a 的定义为“int a[]={1,2,3,4,5};”,则 a[2]=______,数组 b 的定义为“int
b[]=new int[5]; ”, 则 b[2]=______ , 数 组 c 的 定 义 为 “ Object []c=new Object[5]; ”, 则
c[2]=______。
A. sizeof
B. super
C. abstract
D. break
解答:A
4、 下面哪些 java 语句会导致无限循环?(
)
I、 while (true) i = 0;
II、 while (false) i = 1;
III、while (!false) i = 0;
A、仅仅 III
B、I 和 III
A. javac
B. java
C. jdb
D. javap
解答:D
3、 public static void main 方法的参数描述是:(
)
A. String args[]
B. String[] args
C. Strings args[]
D. String args
解答:A,B
4、 在 Java 中,关于 CLASSPATH 环境变量的说法不正确的是:(
解答:C
7、 为 AB 类的一个无形式参数无返回值的方法 method 书写方法头,使得使用类名 AB
作为前缀就可以调用它,该方法头的形式为( )。
A、 static void method( )
B、 public void method( )
boolean b[]=new boolean[5];
System.out.print(a[1]);
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
B. ng
C. java.io
D. java.awt
解答:B
3、 当类的成员未用访问权限修饰符时,Java 认为此成员的访问权限为(
)。
A. private
B. protected
C.friendly
D.public
解答:C
4、 下面哪个关键字不是用来控制对类成员的访问的?(
)
A. public
24、调用数组元素时,用______和______来唯一确定数组中的元素。
25、什么是数组?数组有哪些特点?Java 中创建数组需要哪些步骤?如何访问数组的
第一个元素?
26、编程计算 10~20 的整数的平方值,将结果保存在一个数组中。
27、编写一个程序使之从键盘读入 10 个整数存入整型数组 a 中,然后逆序输出这 10
7
while(sum<=4){ sum=(i+1)*sum; a++; System.out.println("第"+a+"年达到"+sum);
} System.out.println("需要"+a+"年实现两番"); } }
7
8
《Java 语言程序设计基础教程》
第 3 章 类和对象
3.9 练习思考题
B. protected
C. default
D. private
解答:C
5、 下面哪一个特性不是面向对象编程主要体现的( )。
A. 封装性
B. 继承
C. 多态
D. 类
解答:C
6、 不允许作为类及类成员的访问控制符的是( )。
A. public
B. private
C. static
D. protected
个整数。
28、某人有 5 张 3 分和 4 张 5 分的邮票,请编写一个程序,计算由这些邮票中的 1 张
或若干张可以得到多少种不同的邮资。
29、分析写出下列程序完成的功能。
public class sun {
public static void main(String args[]) {
double sum = 0.0;
boolean b[]=new boolean[5];
System.out.print(a[1]);
System.out.println(b[2]);
}
} A. 运行结果为 0false
B. 运行结果为 1true
C. 程序无法通过编译
D. 可以通过编译但结果不确定
解答:A
17、在 Java 的基本数据类型中,char 型采用 Unicode 编码方案,每个 Unicode 码占用
A. IDoLikeTheLongNameClass
B. $byte
C. const
D. _ok
E. 3_case
解答:A,B,D
2、 下面哪一项在 java 中是非法的标识符?( )
A. $user
B. point
C. You&me
D. _endline
解答:C
3、 下列不属于 Java 保留字的是:( )
______字节内存空间,这样,无论是中文字符还是英文字符,都是占用______字节内存空
间。
18、设 x = 2 ,则表达式 ( x + + )/3 的值是______。 19、若 x = 5,y = 10,则 x < y 和 x >= y 的逻辑值分别为______和______。
20、设有数组定义:
1、 下列关于变量的叙述哪个是错的?( )
A. 实例变量是类的成员变量。
B. 在方法中定义的局部变量在该方法被执行时创建。
C. 实例变量用关键字 static 声明。
D. 局部变量在使用前必须被初始化。
解答:C
2、 在 Java 语言中,下列哪个包是编译器自动导入的?( )
A. java.applet
23、已知数组 a 的定义为“int a[]={1,2,3,4,5};”,则 a[2]=______,数组 b 的定义为“int
b[]=new int[5]; ”, 则 b[2]=______ , 数 组 c 的 定 义 为 “ Object []c=new Object[5]; ”, 则
c[2]=______。
3
4
《Java 语言程序设计基础教程》
int l = 0;
do {
System.out.println("Doing it for l is:" + l);
} while (--l > 0);
System.out.println("Finish");
}
}
A. Doing it for l is 3
B. .class
C. .html
D. .exe
解答:B
6、 开发与运行 Java 程序需要经过的三个主要步骤为____________、____________和
____________。
7、 如果一个 Java Applet 源程序文件只定义有一个类,该类的类名为 MyApplet,则类
MyApplet 必须是______类的子类并且存储该源程序文件的文件名为______。
31、如果我国经济以每年 10%的速度保持稳定增长,请编写一个程序,计算每年达到
多少,多少年可以实现总量翻两番。
class exA4_1{
public static void main(String args[]){
int a=0;
double i=0.10,sum=1;
6
《Java 语言程序设计基础教程》
解答:B
14、下列语句有错误的是:( )
A. int []a;
B. int []b=new int[10];
C. int c[]=new int[]; 解答:C
D. int d[]=null;
15、下列语句有错误的是:( )
A. int a[][]=new int[5][5]; B. int [][]b=new int[5][5];
int[] x={2,3,-8,7,9};
int max=x[0];
for(int i=1;i<x.length;i++){
if(x[i]>max)
max=x[i];
}
System.out.println(max);
A. 2
B. -8
4
《Java 语言程序设计基础教程》
5
C. 7
D. 9
解答:D
12、设 x = 1 , y = 2 , z = 3,则表达式 y+=z--/++x 的值是( )
if (i % 2 == 1)
s += MyIntArray[i];
System.out.println(s);
21、数组对象的长度在数组对象创建之后,就______改变。数组元素的下标总是从
______开始。
22、对于数组 int[][]t={{1,2,3},{4,5,6}}来说,t.length 等于______,t[0].length 等于______。
)
A. CLASSPATH 一旦设置之后不可修改,但可以将目录添加到该环境变量中。
B. 编译器用它来搜索各自的类文件。
C. CLASSPATH 是一个目录列表。
D. 解释器用它来搜索各自的类文件。
解答:A
5、 编译 Java Application 源文件将产生相应的字节码文件,扩展名为( )
A. .java
解答:C
7、 为 AB 类的一个无形式参数无返回值的方法 method 书写方法头,使得使用类名 AB
作为前缀就可以调用它,该方法头的形式为( )。
A、 static void method( )
B、 public void method( )
规则是怎么样的?
11、编写一个简单的 Java 应用程序,该程序在命令行窗口输出两行文字:“你好,很
高兴学习 Java”和“We are students”。
2
《Java 语言程序设计基础教程》
3
第 2 章 Java 基本的程序设计结构
2.7 练习思考题
1、 从下面选项中,选择三个有效的标示符:( )
C、仅仅 I
D、I, II 和 III
解答:B
5、 下列整型数据类型中,需要内存空间最少的是 (
)。
A. short
B. long
C. int
D. byte
解答:D
6、 下面代码执行后,正确的输出结果是:( )
public class Example {
public static void main(String args[]) {
《Java 语言程序设计基础教程》 练习思考题参考答案
2
《Java 语言程序设计基础教程》
第 1 章 Java 程序设计概述
1.9 练习思考题
1、 Java 运行平台包括三个版本,请选择正确的三项:( )
A. J2EE
B. J2ME
C. J2SE
D. J2E
解答:A,B,C
2、 Java JDK 中反编译工具是:( )
5
6
《Java 语言程序设计基础教程》
int MyIntArray[] = { 10, 20, 30, 40, 50, 60, 70 };
则执行以下几个语句后的输出结果是: