华南理工大学大一JAVA复习题.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《华南理工大学大一JAVA复习题.doc》由会员分享,可在线阅读,更多相关《华南理工大学大一JAVA复习题.doc(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精品文档,仅供学习与交流,如有侵权请联系网站删除2.1从输入对话框读入double型的华氏度,将其转换为摄氏度,并在消息对话框中显示结果。Celsius = (5/9)*(Fahrenheit-32)import javax.swing.JOptionPane;public class Exercise2_1 public static void main(String args) String fahrenheitString = JOptionPane.showInputDialog(null, Enter a temperature in fahrenheit:, Exercise2_1
2、 Input, JOptionPane.QUESTION_MESSAGE); double fahrenheit = Double.parseDouble(fahrenheitString); double celsius = (5.0 / 9.0) * (fahrenheit - 32); System.out.println(The temperature is + celsius + in Celsius); System.exit(0);2.7编写程序将大写字母转换为小写字母,该字符在源代码ASCII中指定为直接量。public class Exercise2_7 public sta
3、tic void main(String args) char uppercase = F; int offset = (int)a - (int)A; char lowercase = (char)(int)uppercase + offset); System.out.print(The lowercase letter is + lowercase);3.1 (三角形有效性验证)读入三角形的三条边并确定输入是否有效。如果任意两条边和大于第三边则输入有效。import javax.swing.JOptionPane;public class Exercise3_1 public stati
4、c void main(String args) String numberString = JOptionPane.showInputDialog(null, Enter the first edge length (double), Exercise3_1 Input, JOptionPane.QUESTION_MESSAGE); double edge1 = Double.parseDouble(numberString); numberString = JOptionPane.showInputDialog(null, Enter the second edge length (dou
5、ble), Exercise3_1 Input, JOptionPane.QUESTION_MESSAGE); / Convert string to double double edge2 = Double.parseDouble(numberString); numberString = JOptionPane.showInputDialog(null, Enter the third edge length (double), Exercise3_1 Input, JOptionPane.QUESTION_MESSAGE); double edge3 = Double.parseDoub
6、le(numberString); System.out.println(Can edges + edge1 + , + edge2 + , and + edge3 + form a triangle? + ( (edge1 + edge2 edge3) & (edge1 + edge3 edge2) & (edge2 + edge3 edge1); System.exit(0);4.1 (千克转换成磅)编一个显示下列表格的程序(1千克为2.2磅)(1kilogram = 2.2 pounds)KilogramsPounds12.236.6197433.4199437.8public clas
7、s Exercise3_8 public static void main(String args) System.out.println(kilogramsttpounds); System.out.println(-); int kilograms = 1; for (int i = 1; i = 100; kilograms += 2, i+) System.out.println(kilograms + tt + kilograms * 2.2);4.18 用嵌套的循环语句,分别编写程序打印下列图案。Pattern 111 21 2 31 2 3 41 2 3 4 51 2 3 4 5
8、 6Pattern 21 2 3 4 5 61 2 3 4 51 2 3 41 2 31 2 /* Print Pattern I */public class Exercise3_23 public static void main(String args) for (int i = 1; i = 6; i+) for (int j = 1; j = i; j+) System.out.print(j + ); System.out.println();/pattern 2public class test public static void main(String args) for (
9、int i = 1; i = 6; i+) for (int j = 1; j = A & c num2) double temp = num1; num1 = num2; num2 = temp; if (num2 num3) double temp = num2; num2 = num3; num3 = temp; if (num1 num2) double temp = num1; num1 = num2; num2 = temp; System.out.println(The sorted numbers are + num1 + + num2 + + num3);6.1读入10个数字
10、,计算它们的平均值并且找出有多少个数字在平均值之上。import javax.swing.*;public class Exercise5_1 public static void main(String args) double numbers = new double10; double sum = 0; for (int i = 0; i numbers.length; i+) String s = JOptionPane.showInputDialog(Enter a number: ); numbersi = Double.parseDouble(s); sum += numbers
11、i; double average = sum / 10; int countGreater = 0; for (int i = 0; i average) countGreater+; System.out.println(The number of values greater than the average is + countGreater); System.exit(0);6.5读入10个数并且显示其中相互不同的数。提示:读入一个数,如果它是新数,则把它存储在数组中;如果数组中已有该数,则把它丢弃。输入结束后,数组中的数都是不同的数。public class Exercise6_5
12、 public static void main(String args) int numbers = new int10; int size = 0; for (int i = 0; i numbers.length; i+) String s = JOptionPane.showInputDialog(null, Enter an integer); int value = Integer.parseInt(s); boolean isInArray = false; for (int j = 0; j size; j+) if (numbersj = value) isInArray =
13、 true; break; if (!isInArray) numberssize = value; size+;7.1 编写名为Rectangle的类表示矩形,这个类包括:l 两个double型的数据域 width and height表示矩形的宽和高,它们的默认值都是1l String类型的数据域 color 表示矩形的颜色,进一步假设所有矩形的颜色都是相同的,默认颜色为白色.l 无参构造方法创建默认矩形.l 一个构造方法创建指定width and height的矩形.l 所有三个数据域的访问器方法和修改器方法;l getArea()方法返回该矩形的面积.l getPerimetet()方
14、法返回它的周长.创建两个Rectangle 对象。设计width 5 and height 15 为第一个对象and width 4.3 and height 40.5为第二个对象。所有 Rectangle对象的颜色为红色。显示两个对象的属性并求出它们的面积和周长。/ Exercise7_1.java: Create the Rectangle classpublic class test public static void main (String args) Rectangle myRectangle = new Rectangle(5, 40); System.out.println(
15、The area of a rectangle with width + myRectangle.getWidth() + and height + myRectangle.getHeight() + is + myRectangle.getArea(); System.out.println(The color is + myRectangle.getColor(); Rectangle yourRectangle = new Rectangle(1.0, 3.5); System.out.println(The area of a rectangle with width + yourRe
16、ctangle.getWidth() + and height + yourRectangle.getHeight() + is + yourRectangle.getArea(); System.out.println(The color is + yourRectangle.getColor();class Rectangle private double width, height; private static String color=red; public Rectangle(double w, double h) width = w; height = h; public dou
17、ble getWidth() return width; public double getHeight() return height; public static String getColor() return color; public static void setColor(String color) Rectangle.color = color; public double getArea() return width*height; public double getPerimeter() return (width*2+height*2);8.21假设文本文件名为8-21.
18、tXt,包含未指定个数的分数。编写程序,从文件中读入分数并显示它们的和与平均值。分数被空格分开。import java.util.*;import java.io.*;public class Exercise8_21 public static void main(String args) throws Exception Scanner input = new Scanner(new File(Exercise8_21.txt); double sum = 0; while (input.hasNext() sum += input.nextDouble(); System.out.pri
19、ntln(Total is + sum);9.1设计名为Triangle的类, 扩展GeometricObject.该类包括:l 三个名为side1,side2, 和side3 的double数据域,三角形三边默认值为1.0 ;l A一个无参构造方法创建默认的三角形.l 指定side1, side2,and side3的值,创建三角形的构造方法.l 三个数据域的访问器方法。l 名为getArea()的方法返回三角形的面积.l 名为getPerimetet()的方法返回三角形的周长.l 名为toString()的方法返回描述三角形的字符串.计算三角形面积的公式执行如下:Return “Trian
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 华南理工大学 大一 JAVA 复习题
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内