当前位置:文档之家› java程序设计教程第七版 实验3

java程序设计教程第七版 实验3

java程序设计教程第七版 实验3
java程序设计教程第七版 实验3

Chapter 3: Using Classes and Objects Lab Exercises

Topics Lab Exercises

String Class Prelab Exercises

Working with Strings

Random Class Rolling Dice

Math Class Computing Distance

Formatting Classes Formatting Output

Enumerated Types Playing with Cards

Wrapper Classes Experimenting with the Integer Class

Panels Panels Nested

Prelab Exercises

Sections 3.2-3.5

These exercises focus on the String, Random, and Math classes defined in the Java Standard Class Library. The main concepts are in the text in sections 3.2-3.5. The goals of the lab are for you to gain experience with the following concepts: ? Declaring a variable to be a reference to an object—for example, the following declares the variable quotation to be a reference to a String object:

String quotation;

? Declaring a variable to be a reference to an object and creating the object (instantiating it) using the new operator—for example,

String quotation = new String("I think, therefore I am.");

Random generator = new Random();

? Invoking a method to operate on an object using the dot operator—for example,

quotation.length()

invokes the length method which returns the length of the quotation String or

quotation.toLowerCase()

quotation except all letters are lower case. These invocations would be used in a program in a place appropriate for an integer (in the first case) or a String (in the second case) such as an assignment statement or a println statement.

? Invoking

static or class methods—these are methods that are invoked using the class name rather than an object name.

The methods in the Math class are static methods (basically because we don't need different instances of Math whereas there are lots of different String objects). Examples are

Math.sqrt(2) (which returns the square root of 2)

and

Math.pow(3, 2) (which returns 32)

? Importing the appropriate packages—usually when you use classes from a library you need to put the import declaration at the top of your program. The exception is for classes defined in the https://www.doczj.com/doc/c56263988.html,ng package (this includes String and Math) which is automatically imported into every Java program.

Exercises

1. Fill in the blanks in the program below as follows: (Section 3.2, especially the example in Listing 3.1, should be helpful):

(a) declare the variable town as a reference to a String object and initialize it to "Anytown, USA".

(b) write an assignment statement that invokes the length method of the string class to find the length of the college

String object and assigns the result to the stringLength variable

(c) complete the assignment statement so that change1 contains the same characters as college but all in upper case

(d) complete the assignment statement so that change2 is the same as change1 except all capital O's are replaced with

the asterisk (*) character.

(e) complete the assignment statement so that change3 is the concatenation of college and town (use the concat method

of the String class rather than the + operator)

// **************************************************

// StringPlay.java

//

// Play with String objects

// **************************************************

public class StringPlay

{

public static void main (String[] args)

{

String college = new String ("PoDunk College");

________________________________________________________; // part (a)

int stringLength;

String change1, change2, change3;

________________________________________________________; // part (b)

System.out.println (college + " contains " + stringLength + " characters.");

changel = _____________________________________________; // part (c)

change2 = _____________________________________________; // part (d)

change3 = _____________________________________________; // part (e)

System.out.println ("The final string is " + change3);

}

}

2. The following program should read in the lengths of two sides of a right triangle and compute the length of the

hypotenuse (recall that the length of the hypotenuse is the square root of side 1 squared plus side 2 squared). Complete it by adding statements to read the input from the keyboard and to compute the length of the hypotenuse (you need to use a Math class method for that).

// *******************************************************************

// RightTriangle.java

//

// Compute the length of the hypotenuse of a right triangle

// given the lengths of the sides

// *******************************************************************

import java.util.Scanner;

public class RightTriangle

{

public static void main (String[] args)

{

double side1, side2; // lengths of the sides of a right triangle

double hypotenuse; // length of the hypotenuse

Scanner scan = new Scanner(System.in);

// Get the lengths of the sides as input

System.out.print ("Please enter the lengths of the two sides of " +

"a right triangle (separate by a blank space): ");

-------------------------------------------------------------;

-------------------------------------------------------------;

// Compute the length of the hypotenuse

-------------------------------------------------------------;

// Print the result

System.out.println ("Length of the hypotenuse: " + hypotenuse);

}

}

3. In many situations a program needs to generate a random number in a certain range. The Java Random class lets the

programmer create objects of type Random and use them to generate a stream of random numbers (one at a time). The following declares the variable generator to be an object of type Random and instantiates it with the new operator.

Random generator = new Random();

The generator object can be used to generate either integer or floating point random numbers using either the nextInt method (either with no parameter or with a single integer parameter) or nextFloat (or nextDouble) methods,

respectively. The integer returned by nextIn(t could be any valid integer (positive or negative) whereas the number returned by nextInt(n) is a random integer in the range 0 to n-1. The numbers returned by nextFloat() or nextDouble() are floating point numbers between 0 and 1 (up to but not including the 1). Most often the goal of a program is to generate a random integer in some particular range, say 30 to 99 (inclusive). There are several ways to do this:

? Using nextInt(): This way we must use the % operator to reduce the range of values—for example,

Math.abs(generator.nextInt()) % 70

will return numbers between 0 and 69 (because those are the only possible remainders when an integer is divided by

70 - note that the absolute value of the integer is first taken using the abs method from the Math class). In general,

using % N will give numbers in the range 0 to N -1. Next the numbers must be shifted to the desired range by

adding the appropriate number. So, the expression

Math.abs(generator.nextInt()) % 70 + 30

will generate numbers between 30 and 99.

The expression

nextInt(70):

? Using

generator.nextInt(70)

will return numbers between 0 and 69 (inclusive). Next the numbers must be shifted to the desired range by adding the appropriate number. So, the expression

generator.nextInt(70) +30

will generate numbers between 30 and 99.

? Using nextFloat: In this case, we must multiply the result of nextFloat to expand the range—for example, generator.nextFloat() * 70

returns a floating point number between 0 and 70 (up to but not including 70). To get the integer part of the number we use the cast operator:

(int) (generator.nextFloat() * 70)

The result of this is an integer between 0 and 69, so

(int) (generator.nextFloat() * 70) + 30

shifts the numbers by 30 resulting in numbers between 30 and 99.

The method nextFloat can be replaced by nextDouble to get double precision floating point numbers rather than single precision.

Fill in the blanks in the following program to generate the random numbers as described in the documentation. NOTE that that java.util.Random must be imported to use the Random class.

// **************************************************

// LuckyNumbers.j ava

//

// To generate three random "lucky" numbers

// **************************************************

import java.util.Random;

public class LuckyNumbers

{

public static void main (String[] args)

{

Random generator = new Random();

int lucky1, lucky2, lucky3;

// Generate lucky1 (a random integer between 50 and 79) using the

// nextInt method (with no parameter)

luckyl = _____________________________________________________;

// Generate lucky2 (a random integer between 90 and 100) using the

// nextInt method with an integer parameter

lucky 2 = ____________________________________________________;

// Generate lucky3 (a random integer between 11 and 30) using nextFloat lucky 3 = ____________________________________________________;

System.out.println ("Your lucky numbers are " + lucky1 + ", " + lucky2

+ ", and " + lucky3);

}

}

Working with Strings

The following program illustrates the use of some of the methods in the String class. Study the program to see what it is doing.

// ***************************************************************

// StringManips.j ava

//

// Test several methods for manipulating String objects

// ***************************************************************

import java.util.Scanner;

public class StringManips

{

public static void main (String[] args)

{

String phrase = new String ("This is a String test.");

int phraseLength; // number of characters in the phrase String

int middleIndex; // index of the middle character in the String

String firstHalf; // first half of the phrase String

String secondHalf; // second half of the phrase String

String switchedPhrase; //a new phrase with original halves switched

// compute the length and middle index of the phrase

phraseLength = phrase.length();

middleIndex = phraseLength / 2;

// get the substring for each half of the phrase

firstHalf = phrase.substring(0,middleIndex);

secondHalf = phrase.substring(middleIndex, phraseLength);

// concatenate the firstHalf at the end of the secondHalf

switchedPhrase = secondHalf.concat(firstHalf);

// print information about the phrase

System.out.println();

System.out.println ("Original phrase: " + phrase);

System.out.println ("Length of the phrase: " + phraseLength +

" characters");

System.out.println ("Index of the middle: " + middleIndex);

System.out.println ("Character at the middle index: " +

phrase.charAt(middleIndex));

System.out.println ("Switched phrase: " + switchedPhrase);

System.out.println();

}

}

The file StringManips.java contains this program. Save the file to your directory and compile and run it. Study the output and make sure you understand the relationship between the code and what is printed. Now modify the file as follows:

1.Declare a variable of type String named middle3 (put your declaration with the other declarations near the top of the

program) and use an assignment statement and the substring method to assign middle3 the substring consisting of the middle three characters of phrase (the character at the middle index together with the character to the left of that and the one to the right - use variables, not the literal indices for this particular string). Add a println statement to print out the result. Save, compile, and run to test what you have done so far.

2. Add an assignment statement to replace all blank characters in switchedPhrase with an asterisk (*). The result should be

stored back in switchedPhrase (so switchedPhrase is actually changed). (Do not add another print—place your statement in the program so that this new value of switchedPhrase will be the one printed in the current println statement.) Save, compile, and run your program.

3. Declare two new variables city and state of type String. Add statements to the program to prompt the user to enter their

hometown—the city and the state. Read in the results using the appropriate Scanner class method - you will need to have the user enter city and state on separate lines. Then using String class methods create and print a new string that consists of the state name (all in uppercase letters) followed by the city name (all in lowercase letters) followed again by the state name (uppercase). So, if the user enters Lilesville for the city and North Carolina for the state, the program should create and print the string

NORTH CAROLINAlilesvilleNORTH CAROLINA

Rolling Dice

Write a complete Java program that simulates the rolling of a pair of dice. For each die in the pair, the program should generate a random number between 1 and 6 (inclusive). It should print out the result of the roll for each die and the total roll (the sum of the two dice), all appropriately labeled. You must use the Random class. The RandomNumbers program in listing 3.2 of the text may be helpful.

Computing Distance

The file Distance.java contains an incomplete program to compute the distance between two points. Recall that the distance between the two points (x1, y1) and (x2, y2) is computed by taking the square root of the quantity (x1 - x2)2 + (y1 - y2)2. The program already has code to get the two points as input. You need to add an assignment statement to compute the distance and then a print statement to print it out (appropriately labeled). Test your program using the following data: The distance between the points (3, 17) and (8, 10) is 8.6023... (lots more digits printed); the distance between (-33,49) and (-9, -15) is 68.352.…

// ************************************************************

// Distance.java

//

// Computes the distance between two points

// ************************************************************

import java.util.Scanner;

public class Distance

{

public static void main (String[] args)

{

double x1, y1, x2, y2; // coordinates of two points

double distance; // distance between the points

Scanner scan = new Scanner(System.in);

// Read in the two points

System.out.print ("Enter the coordinates of the first point " +

"(put a space between them): ");

x1 = scan.nextDouble();

y1 = scan.nextDouble();

System.out.print ("Enter the coordinates of the second point: ");

x2 = scan.nextDouble();

y2 = scan.nextDouble();

// Compute the distance

// Print out the answer

}

}

Formatting Output

File Deli.java contains a partial program that computes the cost of buying an item at the deli. Save the program to your directory and do the following:

1. Study the program to understand what it does.

2. Add the import statements to import the DecimalFormat and NumberFormat classes.

3. Add the statement to declare money to be a NumberFormat object as specified in the comment.

4. Add the statement to declare fmt to be a DecimalFormat object as specified in the comment.

5. Add the statements to print a label in the following format (the numbers in the example output are correct for input

of $4.25 per pound and 41 ounces). Use the formatting object money to print the unit price and total price and the formatting object fmt to print the weight to 2 decimal places.

***** CSDeli *****

Unit Price: $4.25 per pound

Weight: 2.56 pounds

TOTAL: $10.89

// ************************************************************

// DeliFormat.java

//

// Computes the price of a deli item given the weight

// (in ounces) and price per pound -- prints a label,

// nicely formatted, for the item.

//

// ************************************************************

import java.util.Scanner;

public class Deli

{

// ---------------------------------------------------

// main reads in the price per pound of a deli item

// and number of ounces of a deli item then computes

// the total price and prints a "label" for the item

// ---------------------------------------------------

public static void main (String[] args)

{

final double OUNCES_PER_POUND = 16.0;

double pricePerPound; // price per pound

double weightOunces; // weight in ounces

double weight; // weight in pounds

double totalPrice; // total price for the item

Scanner scan = new Scanner(System.in);

// Declare money as a NumberFormat object and use the

// getCurrencyInstance method to assign it a value

// Declare fmt as a DecimalFormat object and instantiate

// it to format numbers with at least one digit to the left of the

// decimal and the fractional part rounded to two digits.

// prompt the user and read in each input

System. out. println ("Welcome to the CS Deli! ! \n ")

;

System.out.print ("Enter the price per pound of your item: ");

pricePerPound = scan.nextDouble();

System.out.print ("Enter the weight (ounces): ");

weightOunces = scan.nextDouble();

// Convert ounces to pounds and compute the total price

weight = weightOunces / OUNCES_PER_POUND;

totalPrice = pricePerPound * weight;

// Print the label using the formatting objects

// fmt for the weight in pounds and money for the prices

}

}

Playing With Cards

Write a class that defines an enumerated type named Rank with values ace, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king. The main method should do the following:

1. Declare variables highCard, faceCard, card1, and card2 of type Rank.

2. Assign highCard to be an ace, faceCard to be a jack, queen or king (your choice), and card1 and card2 to be two

different numbered cards (two through ten - your choice).

3. Print a line, using the highCard and faceCard objects, in the following format:

A blackjack hand: ace and ....

The faceCard variable should be printed instead of the dots.

4. Declare two variables card1 Val and card2Val of type int and assign them the face value of your card1 and card2

objects. Use your card1 and card2 variables and the ordinal method associated with enumerated types. Remember that the face value of two is 2, three is 3, and so on so you need to make a slight adjustment to the ordinal value of the enumerated type.

5. Print two lines, using the card1 and card2 objects and the name method, as follows:

A two card hand: (print card1 and card2)

Hand value: (print the sum of the face values of the two cards)

Experimenting with the Integer Class

Wrapper classes are described on pages 138-140 of the text. They are Java classes that allow a value of a primitive type to be "wrapped up" into an object, which is sometimes a useful thing to do. They also often provide useful methods for manipulating the associated type. Wrapper classes exist for each of the primitive types: boolean, char, float, double, int, long, short, and byte.

Write a program IntWrapper that uses the constants and methods of the Integer class (page 140 for a short list, pages 819-820 for a complete list) to perform the following tasks. Be sure to clearly label your output and test your code for each task before proceding.

1. Prompt for and read in an integer, then print the binary, octal and hexadecimal representations of that integer.

2. Print the maximum and minimum possible Java integer values. Use the constants in the Integer class that hold these

values — don't type in the numbers themselves. Note that these constants are static (see the description on page 140 and the signature on page 819).

3. Prompt the user to enter two decimal integers, one per line. Use the next method of the Scanner class to read each of

them in. (The next method returns a String so you need to store the values read in String variables, which may seem strange.) Now convert the strings to ints (use the appropriate method of the Integer class to do this), add them

together, and print the sum.

Nested Panels

The program NestedPanels.java is from Listing 3.8 of the text. Save the program to your directory and do the following:

1. Compile and run the program. Experiment with resizing the frame and observe the effect on the components.

2. Modify the program by adding a third subpanel that is twice as wide, but the same height, as the other two

subpanels. Choose your own label and color for the subpanel (the color should not be red, green, or blue). Add the panel to the primary panel after the other two panels.

3. Compile and run the modified program. Again, experiment with resizing the frame and observe the effect on the

components.

4. Now add a statement to the program to set the preferred size of the primary panel to 320 by 260. (What would be the

purpose of this?). Compile and run the program to see if anything changed.

5. Now add another panel with background color blue and size 320 by 20. Add a "My Panels" label to this panel and

then add this panel to the primary panel before adding the other panels. Compile and run the program. What was the effect of this panel?

// ************************************************************

// NestedPanels.java Author: Lewis/Loftus

//

// Demonstrates a basic component hierarchy.

// ************************************************************

import j ava.awt.*;

import javax.swing.*;

public class NestedPanels

{

// --------------------------------------------------------

// Presents two colored panels nested within a third.

// --------------------------------------------------------

public static void main (String[] args)

{

JFrame frame = new JFrame ("Nested Panels");

frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

// Set up first subpanel

JPanel subPanel1 = new JPanel()

;?

subPanel1.setPreferredSize (new Dimension(150, 100));

subPanel1.setBackground (Color.green);

JLabel label1 = new JLabel ("One");

subPanel1.add (label1)003B

// Set up second subpanel

JPanel subPanel2 = new JPanel();

subPanel2.setPreferredSize (new Dimension(150, 100));

subPanel2.setBackground (Color.red);

JLabel label2 = new JLabel ("Two");

subPanel2.add (label2);

// Set up primary panel

JPanel primary = new JPanel();

primary.setBackground (Color.blue);

primary.add (subPanel1);

primary.add (subPanel2);

frame.getContentPane().add(primary);

frame. pack ()

;

frame.setVisible(true);

}

}

java程序设计基础(第3版)实验指导答案 第三章

实验10 import java.util.*; public class shiyan10 { public static void main(String[] args) { int a=0,b=0,c=0,max=0; Scanner reader=new Scanner(System.in); System.out.println("从键盘输入第一个整数"); a=reader.nextInt(); System.out.println("从键盘输入第二个整数"); b=reader.nextInt(); System.out.println("从键盘输入第三个整数"); c=reader.nextInt(); if(a>b) max=a; else max=b; if(c>max) max=c; System.out.println("最大的数是"+max); } }//在程序中输入三个整数,比较它们的大小,输出最大的数 实验11 public class shiyan11 { public static void main(String[] args) { int s=0; for(int i=0;i<100;i++) { s=s+i; i++; } System.out.println("1+3+5+···+99="+s); } }//用for循环语句求1+3+5+···+99的值 实验12 import java.util.*; public class shiyan12 {

public static void main(String[] args) { int a=0,i=1,s=0; Scanner reader=new Scanner(System.in); while(a<50||a>100) { System.out.println("从键盘输入一个50~100的整数"); a=reader.nextInt(); } System.out.println("你输入的数是"+a); while(i<=a) { s=s+i; i++; } System.out.println("1+2+3+···+"+a+"="+s); } } //编写从键盘输入一个范围在50~100的整数,如果不正确,则继续输入;然后求1到输入整数的累加 实验13 public class shiyan13 { public static void main(String[]args) { int i=100,s=0; do { s=s+i; i--; } while(i>0); System.out.println("100+99+98+···+2+1="+s); } } //用do-while语句求100+99+···+2+1的值 实验14 import java.util.*; public class shiyan14 { public static void main(String[] args)

Java程序设计实例教程考试题

Java程序设计练习题 一、选择题 1、为使Java程序独立于平台,Java虚拟机把字节码与各个操作系统及硬件( A ) A)分开B)结合 C)联系D)融合 2、Java语言与C++语言相比,最突出的特点是( C ) A)面向对象B)高性能 C)跨平台D)有类库 3、下列Java源程序结构中前三种语句的次序,正确的是(D) A)import,package,public class B)import必为首,其他不限 C)public class,package,import D),import,public class 4、在JDK目录中,Java程序运行环境的根目录是( A ) A)bin B)demo C)lib D)jre 5、下列运算符中属于关系运算符的是(A ) A)== B).= C)+= D)-= 6、下列布尔变量定义中,正确并且规范的是( B ) A)BOOLEAN canceled=false; B)boolean canceled=false; C)boolean CANCELED=false; D)boolean canceled=FALSE; 7、下列关键字中可以表示常量的是( A ) A)final B)default C)private D)transient 8、下列运算符中,优先级最高的是( A ) A)++ B)+ C)* D)> 9、Java中的基本数据类型int在不同的操作系统平台的字长是( B ) A)不同的B)32位 C)64位D)16位

10、给一个short类型变量赋值的范围是( C ) A)-128 至 +127 B)-2147483648至 +2147483647 C)-32768至 +32767 D)-1000至 +1000 11、下列运算中属于跳转语句的是( D ) A)try B)catch C)finally D)break 12、switch语句中表达式(expression)的值不允许用的类型是( C ) A)byte B)int C)boolean D)char 13、下列语句中,可以作为无限循环语句的是( A ) A)for(;;) {} B)for(int i=0; i<10000;i++) {} C)while(false) {} D)do {} while(false) 14、下列语句中执行跳转功能的语句是( C ) A)for语句B)while语句 C)continue语句D)switch语句 15、下列表达式中,类型可以作为int型的是( C ) A)“abc”+”efg”B)“abc”+’efg’ C)‘a’+’b’D)3+”4” 17、数组中各个元素的数据类型是( A ) A)相同的B)不同的 C)部分相同的D)任意的 18、在Java语言中,被成为内存分配的运算符是( A ) A)new B)instance of C)[] D)() 19、接口中,除了抽象方法之外,还可以含有( B ) A)变量B)常量 C)成员方法D)构造方法 20、下列能表示字符串s1长度的是( A ) A)s1.length()B)s1.length C)s1.size D)s1.size() 21、StringBuffer类字符串对象的长度是( C ) A)固定B)必须小于16个字符 C)可变D)必须大于16个字符 22、构造方法名必须与______相同,它没有返回值,用户不能直接调用它,只能通过new调用。( A ) A)类名B)对象名 C)包名D)变量名 23、子类继承了父类的方法和状态,在子类中可以进行的操作是( D ) A)更换父类方法B)减少父类方法 C)减少父类变量D)添加方法 24、String、StingBuffer都是______类,都不能被继承。( C )

java程序设计基础(含参考答案)

“Java程序设计基础”课程习题 一、填空 1.Java程序分两类___Applet___和application,Java Application 类型的程序,程序从 ___main方法___开始执行。 2.定义一个Java类时,通过关键字__extends____指明该类的父类。一个类可以有___1___ 个父类。 3.用public修饰的类称为_公有类或公用类__。用public修饰的类成员称为公有成员。被 说明为public的内容可以被__所有其他类___ 使用。如果public类文件与使用它的类文件不在同一目录中,需要通过__import____语句引入。 4.用___private___ 修饰的类成员称为私有成员。私有成员只能在__本类__ 中使用。 5.如果子类定义的成员变量与父类的成员变量同名,称为___方法覆盖___ ,要表明使用 子类的成员变量,可以在成员变量前加上关键字__super___ 。 6.____Object__ 类是Java类库中所有类的父类。 7.Java字符使用__16位的字符集,该字符集成为__Unicode____ 。 8.当子类中定义的方法与父类方法同名时,称子类方法___覆盖___ 父类方法,子类默认 使用自己的方法。使用父类的同名方法,必须用关键字__super__ 说明。 9.Java源程序文件名的后缀是___.java___,Java字节码文件名的后缀是_.class_____。 10.Java类名的第一个字母通常要求___大写___。 11.Java程序由____类__组成,每个程序有一个主类,Java程序文件名应与____主__类的 名称相同。 12.Java__Application_类型的程序需要main()方法,程序从__main____开始执行。 13.布尔型数据类型的关键字是_boolean__ ,占用位数是___1位___ ,有__true__ 和_false_ 两种值。整型数可以采用_十_ 、__八_ 和__十六_三种进制表示。 14.八进制整数以数字__0_开头。十六进制整数以_0x或0X_ 开头。 15.int整型数占用__32位内存。long整型数占用__64 位内存。 16.127L表示__长整型____ 常量。 17.根据占用内存长度将浮点常量分为_double_____ 和__float____ 两种。 18.单精度浮点常量占用__32_ 位内存,双精度浮点常量占用__64 位内存。 19.在Java语言中,字符串“ABC\tD\b\n”中包括__7个字符。 20.数学关系44&&x<9____ 。数学关系x>3且x<=10对应 的Java表达式是_x>3&&x<=10。数学关系x>3或x<-10对应的Java表达式是_x>3||x<-10_。 21.逻辑表达式true&&false&&true的结果是_false_ 。 22.__new__ 运算符的作用是根据对象的类型分配内存空间。当对象拥有内存空间时,会 自动调用类中的构造方法为对象_初始化_。 23.省略访问修饰符的类只能被同_一包_中的类使用,称之具有包访问特性。 24.用public修饰的类称为_公共类_。用public修饰的类成员称为公共成员。被说明为public 的内容可以被_所有类_ 使用。如果public类文件与使用它的类文件不在同一目录中,需要通过_import_语句引入。 25.用_private_ 修饰的类成员称为私有成员。私有成员只能在_本类使用。 26.在类中可以定义多个具有相同名称、但参数不同的方法,这种做法称为__方法重载_ 。 27.如果子类定义的成员变量与父类的成员变量同名,要表明使用子类的成员变量,可以在 成员变量前加上关键字__this__。

Java程序设计-实验报告1-模板 (1)

实验报告 课程名称Java程序设计 实验项目实验一类和对象 系别_________计算机_________ 专业/班级_______计算机类/1402______ 姓名_____李馨雪________ 实验日期______2015.10.10______ 成绩_______________________ 指导教师

一、实验题目:实验一类和对象 二、实验内容: (1)用类描述计算机中CPU的速度和硬盘的容量。要求Java应用程序有4个类,名字分别是PC、CPU、HardDisk和Test,其中Test是主类。 1)PC类与CPU类和HardDisk类关联的UML图如图所示。 其中,CPU类要求getSpeed()返回speed的值,setSpeed(int m)方法 将参数m的值赋值给speed。 HardDisk类要求getAmount()返回amount的值,setAmount(int m)方 法将参数m的值赋值给amount。 PC类要求setCPU(CPU c)将参数c的值赋值给cpu,要求setHardDisk (HardDisk h)方法将参数h的值赋值给HD,要求show()方法能显示 cpu的速度和硬盘的容量。 2)主类Test的要求 main()方法中创建一个CPU对象cpu,其speed设置为2200; main()方法中创建一个HardDisk对象disk,其amount设置为200; main()方法中创建一个PC对象pc, pc调用setCPU方法,实参是cpu;调用setHardDisk方法,实参是 disk;调用show方法。 (2)设计一个动物声音“模拟器”,希望模拟器可以模拟许多动物的叫声,要求如下: 1)编写接口Animal,有2个抽象方法cry()和getAnimaName(); 2)编写模拟器类Simulator,该类有一个playSound(Animal animal)方法,其形参是Animal类型,可以调用实现Animal接口的类所重写的cry()方法播放具体动物的声音,调用重写方法显示动物种类的名称; 3)编写实现Animal接口的Dog类和Cat类。具体的UML图如下所示:4)编写主类Application,其main方法中至少包含如下代码: Simulator si=new Simulator();

Java语言程序设计基础教程习题解答

《Java语言程序设计基础教程》练习思考题参考答案

第1章 Java程序设计概述 练习思考题 1、 Java运行平台包括三个版本,请选择正确的三项:() A. J2EE B. J2ME C. J2SE D. J2E 解答:A,B,C 2、 Java JDK中反编译工具是:() 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环境变量的说法不正确的是:() A. CLASSPATH一旦设置之后不可修改,但可以将目录添加到该环境变量中。 B. 编译器用它来搜索各自的类文件。 C. CLASSPATH是一个目录列表。 D. 解释器用它来搜索各自的类文件。 解答:A 5、编译Java Application源文件将产生相应的字节码文件,扩展名为() A. .java B. .class C. .html D. .exe 解答:B 6、开发与运行Java程序需要经过的三个主要步骤为____________、____________和____________。 7、如果一个Java Applet源程序文件只定义有一个类,该类的类名为MyApplet,则类MyApplet必须是______类的子类并且存储该源程序文件的文件名为______。 8、如果一个Java Applet程序文件中定义有3个类,则使用Sun公司的JDK编译器编译该源程序文件将产生______个文件名与类名相同而扩展名为______的字节码文件。 9、开发与运行Java程序需要经过哪些主要步骤和过程? 10、Java程序是由什么组成的?一个程序中必须要有public类吗?Java源文件的命名规则是怎么样的? 11、编写一个简单的Java应用程序,该程序在命令行窗口输出两行文字:“你好,很高兴学习Java”和“We are students”。

java课程设计实验报告

一实验目的 加深学生对课堂讲授内容的理解,从计算机语言的基本概念、程序设计的基本方法、语法规则等方面加深理解,打好程序设计、开发软件的良好基础。在上机实验中,提高学生对Java语言各部分内容的综合使用能力,逐步掌握Java语言程序设计的规律与技巧。在对Java 程序的调试过程中,提高学生分析程序中出现的错误和排除这些错误的能力。通过上机实践,加深学生对计算机软件运行环境,以及对操作系统与计算机语言支持系统相互关系的了解。 二、实验要求 (1)问题描述准确、规范; (2)程序结构合理,调试数据准确、有代表性; (3)界面布局整齐,人机交互方便; (4)输出结果正确; (5)正确撰写实验报告。 三、设计内容 1、计算器 计算器要有GUI界面,用户可以输入所需计算的数值,可以进行加、减、乘、除四种最基本的运算和混合运算,可以求一个数值的平方及倒数,可以进行阶乘运算,要能运算小数,并且不会产生精度损失,在必要情况下,可以进行四舍五入的运算。允许正负数间的运算。要求使用Applet实现该计算器,当用浏览器运行程序时,点击网页中的按钮,则计算器弹出,浮在网页上,再次点击按钮时,计算器消失。 2、文本编辑器 可以设置文本的字体、大小、颜色等基本参数,可以读取计算机中TXT文件,可以生成一个新的TXT文件。其他功能参照windows的文本编辑器。

四.实验步骤 (1)上机实验之前,为课程设计的内容作好充分准备。对每次上机需要完成的任务进行认真的分析,画出程序流程图,手工写出符合任务要求的程序清单,准备出调试程序使用的数据,以便提高上机实验的效率。 (2)按照实验目的和实验内容进行上机操作。录入程序,编译调试,反复修改,直到使程序正常运行,得出正确的输出结果为止。 (3)根据实验结果,写出实验报告。 五. 源代码及运行结果 1.计算器源代码 import .*; import .*; import .*; public class jisuanqi extends WindowAdapter { , "=", "+","n!" ,"关闭" }; static double a, sum=1; static String s, str ;rame(); } public void frame() { etBackground; txt = new TextField(""); (false);ddActionListener(new buttonlistener());ddActionListener(new close()); (this); (new BorderLayout());.计算器运行界面(1)计算器主界面

java程序设计基础实验27

实验27 类的构造方法1 实验要求:编写一个Java程序,在程序中定义Student类,Student类有三个构造方法,分别对不同的属性进行初始化 编写程序如下 class Student //定义类Student. { String name; int age; public Student() //定义无参的构造方法。 { System.out.println("Student()构造方法被调用"); } public Student(String c) //定义有一个参数的构造方法。 { name=c; System.out.println("Student(String newName)构造方法被调用"); } public Student(String a,int b) //定义有两个参数的构造方法。 { name=a; age=b; System.out.println("Student(String newName,intnewAge)构造方法被调用"); } public static void main(String[] args) { Student volu1=new Student(); //创建Student类的一个对象,不传入参数 Student volu2=new Student("张三"); //创建Student类的一个对象,传入一个参数:”张三” Student volu3=new Student("张三",15); //创建Student类的一个对象,传入两个参数:”张三”、15 } } 运行结果如下

程序分析如下: 程序中的Student类有三个构造方法,分别对不同的属性进行初始化。

Java程序设计实用教程_习题解答

习题 1 1.James Gosling 2.需3个步骤: 1)用文本编辑器编写源文件 2)使用Java编译器(javac.exe)编译源文件,得到字节码文件。 3)使用java解释器(java.exe)来解释执行字节码文件。 3.D:\JDK 1) 设置path 对于Windows 2000/2003/XP,右键单击“我的电脑”,在弹出的快捷菜单中选择“属性”,弹出“系统特性”对话框,再单击该对话框中的“高级选项”,然后单击“环境变量”按钮,添加系统环境变量path。如果曾经设置过环境变量path,可单击该变量进行编辑操作,将需要的值d:\jdk\bin加入即可(注意:修改系统环境变量path后要重新打开DOS窗口编译)。或在DOS窗口输入命令行: set path=d:\jdk\bin(注意:用此方法修改环境变量每次打开DOS窗口都需要输入该命令行重新进行设置)。 2) 设置classpath 对于Windows 2000/2003/XP,右键单击“我的电脑”,在弹出的快捷菜单中选择“属性”,弹出“系统特性”对话框,再单击该对话框中的“高级选项”,然后单击“环境变量”按钮,添加系统环境变量classpath。如果曾经设置过环境变量classpath,可单击该变量进行编辑操作,将需要的值d:\jdk\jre\lib\rt.jar;.;加入即可。或在DOS窗口输入命令行: set classpath= d:\jdk\jre\lib\rt.jar;.;。 4.(B)javac 5.Java源文件的扩展名是”.java”,Java字节码的扩展名是”.class” 6.Java应用程序主类的main申明(D)public static void main(String args[])

Java程序设计基础习题答案

Java程序设计基础课后习题参考答案 第2章 1、关于Java Application得入口方法main()得检验: main()方法得参数名就是否可以改变? main()方法得参数个数就是否可以改变? 该方法名就是否可以改变? 参考答案:(1)main()方法得参数名可以改变.(2)main()方法得参数个数不可以改变。(3)该方法名不可以改变。 2、当一个程序没有main()方法时,能编译吗?如果能编译,能运行吗? 参考答案:当一个程序没有main()方法就是,就是可以编译通过得,但就是不能给运行,因为找不到一个主函数入口。 3、下列语句能否编译通过? bytei =127; bytej = 128; longl1 = 999999; long l2= 9999999999; 参考答案:byte i 与long l1可以编译通过。而byte j 与longl2 超出自身数据类型范围,所以编译失败。 4、下列语句能否编译通过? float f1 =3、5; float f2 = 3.5f; 参考答案:java中浮点型得数据在不声明得情况下都就是double型得,如果要表示一个数据就是float型得,必须在数据后面加上“F”或“f”;因此,floatf1 无法编译通过。 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就是不合法得. 7、下列()就是合法得Java标识符。 (1)Counter1 ??(2)$index, (3) name-7 ??(4)_byte

Java程序设计实验报告分析

学生实验报告 (理工类) 课程名称: JAVA程序设计专业班级: 13电子信息工程(2)学生学号: 1305102056 学生姓名:许伟铭 所属院部:软件工程学院指导教师:王倩倩 20 15 ——20 16 学年第 2 学期 金陵科技学院教务处制

实验报告书写要求 实验报告原则上要求学生手写,要求书写工整。若因课程特点需打印的,要遵照以下字体、字号、间距等的具体要求。纸张一律采用A4的纸张。 实验报告书写说明 实验报告中一至四项内容为必填项,包括实验目的和要求;实验仪器和设备;实验内容与过程;实验结果与分析。各院部可根据学科特点和实验具体要求增加项目。 填写注意事项 (1)细致观察,及时、准确、如实记录。 (2)准确说明,层次清晰。 (3)尽量采用专用术语来说明事物。 (4)外文、符号、公式要准确,应使用统一规定的名词和符号。 (5)应独立完成实验报告的书写,严禁抄袭、复印,一经发现,以零分论处。 实验报告批改说明 实验报告的批改要及时、认真、仔细,一律用红色笔批改。实验报告的批改成绩采用百分制,具体评分标准由各院部自行制定。 实验报告装订要求 实验批改完毕后,任课老师将每门课程的每个实验项目的实验报告以自然班为单位、按学号升序排列,装订成册,并附上一份该门课程的实验大纲。

实验项目名称:JAVA编程基础实验学时: 4 同组学生姓名:————实验地点: 1514/A203 实验日期: 2016.04.08 实验成绩: 批改教师:王倩倩批改时间:

一、实验目的和要求 (1)熟练掌握JDK1.7及Eclipse Kepler Service Release 1(下简称Eclipse)编写调试Java应用程序及Java小程序的方法; (2)熟练掌握Java应用程序的结构; (3)了解Java语言的特点,基本语句、运算符及表达式的使用方法; (4)熟练掌握常见数据类型的使用; (5)熟练掌握if-else、switch、while、do-while、for、continue、break、return 语句的使用方法; (6)熟练掌握数组和字符串的使用; (7)调试程序要记录调试过程中出现的问题及解决办法; (8)编写程序要规范、正确,上机调试过程和结果要有记录,不断积累编程及调试经验; (9)做完实验后给出本实验的实验报告。 二、实验仪器和设备 奔腾以上计算机,Windows 操作系统,装有JDK1.7和Eclipse软件。 三、实验过程 (1)分别使用JDK命令行和Eclipse编译运行Java应用程序。记录操作过程。 Java应用程序参考如下: 思考:1. 适当添加注释信息,通过javadoc生成注释文档; 2. 为主方法传递参数“Hello world”字符串,并输出; 3. 压缩生成".jar"文件。 (2)分别使用JDK命令行和Eclipse编译Java Applet,并建立HTML文档运行该Applet。 记录操作过程。 Java小应用程序参考如下:

JAVA程序设计实验报告格式

《JA V A程序设计》实验报告 题目JAVA基础实战——Bank项目 专业及班级计算机科学与技术120?班 姓名________ ______ _____ __ _ 学号_________ __ _____ 指导教师_____ 孙艺珍____ __________ 日期____________2014年11月_____ __

一、实验目的 《Bank项目》以银行业务为背景,由8 组由浅入深的模块构成,通过实验,可以对面向对象的封装性、构造器、引用类型的成员变量、异构数组、继承、多态、方法的重载、方法的重写、包装类、单例模式、异常、集合等技术有更深刻的理解。 二、实验内容: 可以完成银行业务中的基本操作:添加客户,创建异构账户、储蓄卡业务(存钱、取钱)和信用卡业务(包括透支保护等)业务。 三、实验原理 该项目包含Bank、Customer、Account、SavingsAccount、CheckingAccount、OverdraftException、CustomerReport、TestBanking 等8 个类构成,Bank 和Customer、Customer 和Account(SavingsAccount、CheckingAccount)、CheckingAccount 和OverdraftException、CustomerReport 和Bank 及TestBanking 之间以方法参数、成员变量的方式建立引用、依赖关系。 (可以写一下实验过程的思路和采用的技术) 四、实验过程与结果 一些业务逻辑的流程图以及实现的结果 五、分析与讨论 对于实验结果的讨论,对于异常的分析,对于未来功能扩展的设想等等

Java程序设计基础实验报告

Java程序设计基础实验报告50—53 实验50 FileInputStream类的应用 实验目的: 1.学习FileInputStream类的语法格式 2.学习FileInputStream类的使用 实验要求 编写一个Java程序,在main()中生成FileInputStream的一个实例,使它能打开文件myfile.txt,并能够把文件内容显示在屏幕上。 程序运行效果:如图所示 程序模板:package https://www.doczj.com/doc/c56263988.html,.tt; import java.io.*; class ShowFile { public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub int i; FileInputStream fin; fin=new FileInputStream("d:\\myfile.txt"); do{ i=fin.read(); if(i!=-1) System.out.print((char)i); }while(i!=-1); fin.close(); } }

实验51 FileOutputStream类的应用 实验目的: 3.学习FileOutputStream类的语法格式 4.学习FileOutputStream类的使用 实验要求:编写一个Java程序,把文件myfile.txt复制到youfile.txt文件中。 程序运行效果:如图所示 程序模板:package https://www.doczj.com/doc/c56263988.html,.tt; import java.io.*; class CopyFile { public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub int i; FileInputStream fin; FileOutputStream fout; fin=new FileInputStream("d:\\myfile.txt"); fout=new FileOutputStream("d:\\yourfile.txt"); do{ i=fin.read(); if(i!=-1) fout.write(i); }while(i!=-1); fin.close(); fout.close(); System.out.print("myfile.txt内容已经被复制到yourfile.txt文件中"); } }

java实验报告1(程序设计基础)

2012—2013学年第 1 学期 合肥学院数理系 实验报告 课程名称:《面向对象程序设计》 实验项目:程序设计基础 实验类别:综合性□设计性□验证性√ 专业班级:10信息与计算科学班 姓名:学号: 实验地点:校内机房 实验时间:2012.10.22 —2012.10.28 指导教师:钱泽强成绩:

一、实验目的 熟悉Java的编程环境;通过编程掌握Java程序的调试;提高学生的分析问题、解决问题的能力;理解Java语言的基本结构和程序设计方法。 二、实验内容 1、安装并配置JDK,使用Eclipse创建Java程序,并调试运行; 2、了解 Java Application应用程序和Java Applet程序; 3、通过编程掌握Java的基本,并提高分析问题和解决问题的能力。 三、实验方案(程序设计说明) [题目1] 安装Eclipse并配置JDK。 [题目2] 使用Eclipse创建Application程序,并调试运行。 public class test1 { public static void main(String []args) { System.out.println("hello"); } } [题目3] 在Eclipse中创建Applet程序并调试运行。 import java.awt.*; import java.applet.*; public class test2 extends Applet { public void paint(Graphics g) { g.drawString("hello",20,20);} } [题目4] 掌握输入和输出,编写程序求任意两个实型数据的和。 [题目5] 掌握数组的使用,编写程序求一组整型数据的最大值。 四、实验程序和运行结果 请附页记录正确的源程序 五、实验总结 六、教师评语及成绩

Java程序设计基础习题(1-3章)

Java程序设计基础 一、选择题 1、下列标识符不合法的是() A) $variable B) _variable C) variable5 D) break 2、下列哪一个不属于Java的基本数据类型() A) int B) String C) double D) boolean 3、下列答案正确的是() A) int n = 7; int b = 2 * n++; 结果: b = 15, n = 8 B) int n = 7; int b = 2 * n++; 结果: b = 16, n = 8 C) int n = 7; int b = 2 * n++; 结果: b = 14, n = 8 D) int n = 7; int b = 2 * n++; 结果: b = 14, n = 7 4、Java中,下列答案正确的是() A) int n = 7; int b = 2; n/b=3.5; B) int n = 7; int b = 2; n/b=3.5L C) int n = 7; int b = 2; n/b=3.5D D) int n = 7; int b = 2; n/b=3; 6、表示范围大的数据类型要转换成范围小的数据类型,需要用到()类型 转换 A) 隐式B) 强制

7、System.out.print(“1”+2)打印到屏幕的结果是() A) 3 B) 12 C) 1+2 D) 4 8、下面哪个是不合法的变量名称?() A) while-ture B) True C) name D) T1 9、下列变量定义正确的是:() A) boolean status=1; B) float d = 45.6; C) char ch=”a”; D) int k = 1+’1’; 10、某个main()方法中有以下的声明: final int MIN=0; final int MAX=10; int num=5; 下列哪个语句可以用, 来表示”num的值大于等于MIN并且小于等于MAX” ( ) A) !(numMAX) B) num>=MIN && num<=MAX C) num>MIN || num<=MAX D) num>MIN || num

Java程序设计大作业实验报告

目录 一、前言 (2) 二、需求分析 (3) 三、系统总体设计 (3) 3.1系统总体设计系统思路 (3) 3.2数据库设计 (4) 3.2.1 login1表的设计和数据 (4) 3.2.2 student表的设计和数据 (5) 3.2.3 course表的设计和数据 (5) 3.2.4 score表的设计和数据 (5) 3.3系统功能模块设计 (6) 四、系统详细设计 (7) 4.1登录模块 (7) 4.2 学生模块 (7) 4.3 教师模块 (7) 4.4 管理员模块 (8) 五、系统测试及运行结果 (9) 5.1 主界面 (9) 5.2 学生管理中心界面 (9) 5.3 教师管理中心界面 (10) 5.4 管理员管理中心界面 (10)

5.5 查询课表界面 (11) 5.6 查询成绩界面 (11) 5.7 查询教学情况界面 (11) 5.8 查询所有学生成绩界面 (12) 5.9 学生信息管理界面 (12) 5.10 学生成绩管理界面 (13) 5.11 用户管理界面 (13) 六、实验总结 (14) 七、参考文献 (14) 一、前言 随着计算机在人们生活中的普及和网络时代的来临,对信息的要求日益增加,学生信息管理业务受到了较为强烈的冲击,传统的手工管理方式传统的手工管理方式已不能适应现在的信息化社会。如何利用现有的先进计算机技术来解决学生信息管理成为当下的一个重要问题,学生信息管理系统是典型的信息管理系统,其开发主要就是针对前台的页面展示以及后台数据的管理。对于前者,要求应用程序功

能完备,易于使用,界面简单;而对于后者,则要求数据库具有一致性、完整性,并能够依据前台的操作来对应操作后台数据库达到一定的安全性。 本学生信息管理系统主要采用的纯JAVA代码实现图形界面系统的开发,以及数据库知识进行数据的查询,删除,插入和更新。本系统主要分为三个部分:学生模块、教师模块、管理员模块。其中学生模块实现的功能:查询课表信息和查询成绩。教师模块实现的功能:查询课表信息、查询教学情况和查询所有学生的各科成绩。管理员模块实现的功能:课表信息的管理、学生信息管理、学生成绩管理和用户信息管理。 二、需求分析 用JAVA语言实现学生信息管理系统的图形界面的编程。主要实现以下几个重要功能: ①实现三种不同身份(学生、教师、管理员)登录学生信息管理系统。(其中的数据信息保存在数据库中)

Java程序的设计实验报告

信息科学与工程学院 课程设计 题目:图书管理系统 姓名:晓雨颖 学号: 201312140115 201312140120 班级: 13级本科四班物联网 课程: Java程序设计 任课教师梦琳 2014年12月20日

课程设计任务书及成绩评定

目录 1前言 (3) 1.1设计目的 (4) 1.2设计任务 (4) 1.3运行环境 (4) 2总体设计 (5) 2.1设计原理............................................. 错误!未定义书签。3详细设计实现.. (5) 3.1 代码 (5) 3.2 登陆后事件处理 (12) 4心得体会................................................ 错误!未定义书签。

1前言 Java的前身是Oak,它一开始只是被应用于消费性电子产品中。后来它的开发者们发现它还可以被用于更大围的Internet上。1995年,Java语言的名字从Oak编程了Java。1997年J2SE1.1发布。1998年J2SE1.2发布,标志Java2的诞生。十多年来,Java编程语言及平台成功地运用在网络计算及移动等各个领域。Java的体系结构由Java语言、Java class、Java API、Java虚拟机组成。它具有简单、面向对象、健壮、安全、结构中立、可移植和高效能等众多优点。Java支持多线程编程,Java运行时系统在多线程同步方面具有成熟的解决方案。Java的平台标准有Java ME,Java SE和Java EE。Java发展到今天,它的卓越成就及在业界的地位毋庸置疑。目前在众多的支持Java的开发工具中主要的7有Java Development Kit,NetBeans,Jcreator,JBuilder,JDeveloper和Eclipse等。其中Java Development Kit 简称JDK是大多开发工具的基础。以上的每种开发工具都有优缺点,对于开发者来说,重要的是要根据自己的开发规模、开发容和软硬件环境等因素来选择一种合适的开发 工具。

Java程序设计与实践教程_王薇主编_答案

第1章JAVA简介 一、判断题 1.√ 2.√ 3.? 4.? 5.? 6.√ 7.√ 8.√ 9.? 10.? 二、填空题 1.Application Applet 2. 类(字节码文件、目标文件) .class 3.对象 4. 主 5. J2SE J2EE J2ME 三、选择题 1.B 2. D 3.B 4.B 5. A 四、简答题 1.参考答案 Java语言是简单的、面向对象的、分布式的、健壮的、安全的、体系结构中立的、可 移植的、编译解释型的、高性能的、多线程的、动态的等等。 2.参考答案 Java程序执行的具体过程如图1所示。 图1 Java程序的运行机制 3.参考答案 Java程序在计算机在执行要经历以下几个阶段: (1)使用文字编辑软件(例如记事本、写字板、UltraEdit等)或集成开发环境 (JCreater、Eclipse、MyEclipse等)编辑Java源文件,其文件扩展名为.java。 (2)通过编译使.java的文件生成一个同名的.class文件。 (3)通过解释方式将.class的字节码文件转变为由0和1组成的二进制指令执行。 在以上阶段中可以看出Java程序的执行包括了编译和解释两种方式。 第2章Java 语法基础 一、判断题

1. ? 2.√ 3. ? 4.? 5.? 二、填空题 1.10 2. 单精度双精度 3. n%13 !=0?false:true 4.接口 5. false 三、选择题 1.D 2. C 3.D 4.A 5. C 第3章程序流程控制 一、判断题 1.错误 2.? 3.? 4.? 5.√ 二、填空题 1.循环 2. if 3.case switch 4. while do-while 5. continue 三、选择题 1.D 2. C 3.C 4.B 5. C 第4章数组 一、判断题 1. ? 2. √ 3. √ 4. √ 5.? 二、填空题 1.类型 2. new 3.长度 4. 分配空间 5. 3 6 9 三、选择题 1.D 2. A 3.C 4.B 5. B 第5章类和对象 一、判断题 1.√ 2.√ 3.? 4.? 5.√ 6.? 7.√ 8.? 9.? 10.√ 11.√ 12.√ 13.? 14.? 15. ? 二、填空题 1.public default 2. class 属性方法 3.public static void main(String args[]){} 4. new

相关主题
文本预览
相关文档 最新文档