大一的java考试试题_华南理工大学大一JAVA复习题

《华南理工大学大一JAVA复习题》由会员分享,可在线阅读,更多相关《华南理工大学大一JAVA复习题(17页珍藏版)》请在人人文库网上搜索。

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 Input, JOptionPane.QUEST。

2、ION_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 static void main(String args) cha。

3、r 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 static void main(String args) String n。

4、umberString = 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 (double),Exercise3_1 Input, JOptionPane.QU。

5、ESTION_MESSAGE);/ Convert string to doubledouble edge2 = Double.parseDouble(numberString);numberString = JOptionPane.showInputDialog(null,Enter the third edge length (double),Exercise3_1 Input, JOptionPane.QUESTION_MESSAGE);double edge3 = Double.parseDouble(numberString);System.out.println(Can edges。

6、 + 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 class Exercise3_8 public static void main(String args)。

7、 System.out.println(kilogramsttpounds);System.out.println(-);int kilograms = 1; for (int i = 1; i = 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。

8、 numbers are + num1 + + num2 + + num3);6.1读入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 average)countGreater+;System.out.println(The number of values greater than the 。

9、average is + countGreater);System.exit(0);6.5读入10个数并且显示其中相互不同的数。提示:读入一个数,如果它是新数,则把它存储在数组中;如果数组中已有该数,则把它丢弃。输入结束后,数组中的数都是不同的数。public class Exercise6_5 public static void main(String args) int numbers = new int10;int size = 0;for (int i = 0; i (Circle1)o).getRadius()return 1;else if (getRadius() (Cylin。

10、der1)o).findVolume()return 1;else if (findVolume() 0)return o1;elsereturn o2;10.编写一个方法,返回对象组中最大的对象。(查找最大的对象)import java.util.Date;public class Exercise10_9 static int i;public Exercise10_9() public static void main(String args) String strings = CS, Math, Biol, Chem, Phys, Buss,Law, Educ, Elec Engr, 。

11、Mech Engr;Integer list = new Integer10;Date dates = new Date10;for (int i = 0; i list.length; i+)listi = new Integer(int)(Math.random() * 100);for (int i = 0; i list.length; i+)datesi = new Date();System.out.println(Max string is + max(strings);System.out.println(Max integer is + max(list);System.ou。

12、t.println(Max circle is + max(dates);public static Object max(Object a) Comparable max = (Comparable)a0;for (int i = 1; i a.length; i+)if (max.compareTo(ai) 0)max = (Comparable)ai;return max;11.1编写程序,利用Rational类计算下述级数的和:/ Exercise11_1.java: Use the Rational classpublic class Exercise11_1 public stat。

13、ic void main(String args) final int N = 100;Rational sum = new Rational();for (int i = 1; i = N; i+)sum = sum.add(new Rational(i - 1, i);System.out.println(The sum of the first series is + sum + = +sum.doubleValue();17.1编写一个程序,利用异常处理方法处理非数值操作数,然后在编写一个程序,不适用异常处理方法达到同样的目的。程序推出前应该显示一条信息,通知用户发生了操作数类型错误。。

14、/ Exercise17_1.java: Using( NumberFormatException异常)public class Exercise17_1 public static void main (String args) int num1, num2, result = 0;if (args.length != 3) System.out.println(please use java operand1 operator operand2);System.exit(0);try num1 = Integer.parseInt(args0);catch (NumberFormatExc。

15、eption ex) System.out.println(Wrong Input: + args0);return;try num2 = Integer.parseInt(args2);catch (Exception ex) System.out.println(Wrong Input: + args2);return;switch (args1.charAt(0) case +: result = num1 + Integer.parseInt(args2);break;case -: result = Integer.parseInt(args1) -Integer.parseInt(args2);break。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值