说明:

以下为过程化考试平台Java练习题,代码是自己写的,由于我的水平很有限,不免有不妥之处,欢迎指正赐教,谢谢!

1.en_ 2017_ p1_001 Convert Celsius to Fahrenheit

Write a program that reads a Celsius degree in a double value from the console, then converts it to Fahrenheit and displays the
result. The formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32

Note: The class Name must be Main

Example:

Enter a degree in Celsius:

40

output:

40.0 Celsius is 104.0 Frhrenheit

 /******start******/import java.util.Scanner;public class Main {public static void main(String[]args){System.out.println("Enter a degree in Celsius:");Scanner sc = new Scanner(System.in);double cel= sc.nextDouble();double frh= (9.0/5)*cel+32;//In java,9/5 is 1,but 9.0/5 is 1.8.System.out.println("output:");System.out.println(cel+" Celsius is "+frh+" Frhrenheit");}}/******end******/

2.en_ 2017_ p1_002 Compute the volume of a cylinder

Write a program that reads in the radius and length of a cylinder and computes the area(面积) and volume(体积) using the following formulas:

area = radius * radius * π

volume = area * length

use Math.PI as π

Example:

Enter the radius and length of a cylinder:

5.5 12

The area is 95.03317777109125

The volume is 1140.398133253095

    import java.util.Scanner;public class Main {/******start******/public static void main(String[] args){System.out.println("Enter the radius and length of a cylinder:");Scanner sc = new Scanner(System.in);double radius=sc.nextDouble();double length=sc.nextDouble();double area,volume;area = radius * radius *Math.PI;volume = area * length;System.out.println("The area is "+area);System.out.println("The volume is "+volume);}/******end******/}

3.en_ 2017_ p1_003 Convert feet into meters

Write a program that reads a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter.

class Name must be Main

Examples:

Enter a value for feet:

16.5

16.5 feet is 5.0325 meters

    /******start******/import java.util.Scanner;public class Main {public static void main(String[] args){System.out.println("Enter a value for feet:");Scanner sc = new Scanner(System.in);double feet = sc.nextDouble();double meter=feet*0.305;System.out.println(feet+" feet is "+meter+" meters");}}/******end******/

4.en_ 2017_ p1_004 Convert pounds into Kilograms

Write a program that converts pounds into kilograms. The program prompts the user to enter a number in

pounds, converts it to kilograms, and displays the result. One pound is 0.454 kilograms.

Examples:

Enter a number in pounds:

55.5

55.5 pounds is 25.197 kilograms

    /******start******/import java.util.Scanner;public class Main {public static void main(String[] args){System.out.println("Enter a number in pounds:");Scanner sc = new Scanner(System.in);double pound = sc.nextDouble();double kilo=pound * 0.454;System.out.println(pound+" pounds is "+kilo+" kilograms");}}/******end******/

5.en_ 2017_ p1_005 Financial application:calculate tips

Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total

class name Must be Main

Example:

Enter the subtotal and a gratuity rate:

10 16

The gratuity is $1.6 and total is $11.6

    /******start******/import java.util.Scanner;public class Main {public static void main(String[] args){System.out.println("Enter the subtotal and a gratuity rate:");Scanner sc = new Scanner(System.in);float a = sc.nextFloat();float b = sc.nextFloat();float sum1=a*(b/100);String result = String.format("%.1f",sum1);float sum2=a+sum1;System.out.println("The gratuity is $"+result+" and total is $"+sum2);}}/******end******/

6.en_ 2017_ p1_006 Sum the digits in an integer

Write a program that reads an positive integer and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14. Hint: Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93.

class name Must be Main

Example:

Enter a positive number:

98732

The sum of the digits is 29

    /******start******/import java.util.*;public class Main {public  static void main(String[]args){int sum=0;System.out.println("Enter a positive number:");Scanner sc = new Scanner(System.in);int x = sc.nextInt();while(x>0){sum = sum + x%10;x=x/10;}System.out.print("The sum of the digits is "+sum);}}/******end******/

7.en_ 2017_ p1_007 Find the number of years

Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days.

Examples:

Enter the number of minutes:

10000000000

10000000000 minutes is approximately 19025 years and 319 days

    /******start******/import java.util.*;public class Main {public static void main(String[]args){long year,day;System.out.println("Enter the number of minutes:");Scanner sc = new Scanner(System.in);long  min = sc.nextLong();year=min/60/24/365;day=min/60/24-year*365;System.out.println(min+" minutes is approximately "+year+" years and "+day+" days");}}/******end******/

8.en_ 2017_ p1_008 Solve 2*2 linear equations

You can use Cramer’s rule to solve the following system of linear equation:

Write a program that prompts the user to enter a, b, c, d, e, and f and displays the result. If is ad - bc 0, report that “The equation has no solution”

example:

Enter a,b,c,d,e,f:

9.0 4.0 3.0 -5.0 -6.0 -21.0

x is -2.0 and y is 3.0

Enter a,b,c,d,e,f:

1.0 2.0 2.0 4.0 4.0 5.0

equation has no solution

    import java.util.Scanner;public class Main {/******start******/public static void main(String[]args){float x=0.0f,y=0.0f;System.out.println("Enter a,b,c,d,e,f:");Scanner sc = new Scanner(System.in);float a =sc.nextFloat();float b =sc.nextFloat();float c =sc.nextFloat();float d =sc.nextFloat();float e =sc.nextFloat();float f =sc.nextFloat();if(a*d-b*c==0){System.out.println("equation has no solution");}else{x=(e*d-b*f)/(a*d-b*c);y=(a*f-e*c)/(a*d-b*c);System.out.println("x is "+x+" and y is "+y);}}/******end******/}

9.en_ 2017_ p1_009 Check a number

此题代码能在eclipse运行,在exam编译结果只有70分,请大神赐教!
Write a program that prompts the user to enter an integer and checks whether the number is divisible by both 5 and 6, or neither of them, or just one of them. Here are some sample runs for inputs 34, 60, and 25.

Example:

Enter an integer:

34

34 is not divisible by either 5 or 6

Enter an integer:

60

60 is divisible by both 5 and 6

Enter an integer:

25

25 is divisible by 5 or 6, but not both

  /******start******/import java.util.*;public class Main{public static void main (String[] args){System.out.println("Enter an integer:");Scanner sc = new Scanner(System.in);int a = sc.nextInt();int mod1,mod2;mod1=a%5;mod2=a%6;if(mod1==0&&mod2==0){System.out.println(a+" is divisible by both 5 and 6");}else if(mod1!=0&&mod2!=0){System.out.println(a+" is not divisible by either 5 or 6");}else{System.out.println(a+" is divisible by 5 or 6, but not both");}}}/******end******/

10.en_ 2017_ p1_010 compute the sum

Write a program to sum the following series:

Example:

Enter a end number as variable i,end number must be a odd number:

99

The sum is:44.14465232325222

    /******start******/import java.util.Scanner;public class Main {public static void main(String args[]){double j;double sum=0;System.out.println("Enter a end number as variable i,end number must be a odd number:"  );Scanner sc = new Scanner(System.in);double i = sc.nextDouble();for(j=3;j<i;j=j+2){sum=sum+(j-2)/j;}System.out.print("The sum is:"+sum);} }/******end******/

11.en_ 2017_ p1_ 011 decemal to binary

Write a program that prompts the user to enter a decimal integer and displays its corresponding binary value.

Example:

Enter a decimal:

234

The binary of this decimal is:11101010

    /******start******/import java.util.Scanner;public class Main {public static void main(String[] args){System.out.println("Enter a decimal:");Scanner sc = new Scanner(System.in);int a = sc.nextInt();System.out.println("The binary of this decimal is:"+Integer.toBinaryString(a));//转换成八进制把Binary换成Octal//转换成十六进制把Binary换成Hex//解释:Binary是二进制的意思,Octal是八进制的意思,Hex是十六进制的意思。}}/******end******/

12.en_ 2017_ p1_012 Physics:acceleration

Average acceleration is defined as the change of velocity divided by the time taken to make the change, as shown in the following formula:

Write a program that prompts the user to enter the starting velocity in meters/second, the ending velocity in meters/second, and the time span t in seconds, and displays the average acceleration. Here is a sample run:

Examples:

Enter v0 v1 and t:

5.5 50.9 4.5

The average acceleration is 10.088888888888889

    /******start******/import java.util.*;public class Main {public static void main(String[]args){System.out.println("Enter v0 v1 and t:");Scanner sc = new Scanner(System.in);double v0 = sc.nextDouble();double v1 = sc.nextDouble();double t = sc.nextDouble();double a;a=(v1-v0)/t;System.out.println("The average acceleration is "+a);}}/******end******/

13.en_ 2017_ p1_013 Find future dates(此题代码略长,暂时未想到合适的写法,希望大家不吝赐教)

Write a program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1, . . ., and Saturday is 6). Also prompt the user to enter the number of days after today for a future day and display the future day of the week. Here is a sample run:

Example:

Enter today’s day:

Enter the number of days elapsed since today:

1 27

Today is Monday and the future day is Sunday

    import java.util.Scanner;public class Main {/******start******/public static void main(String[]args){System.out.println("Enter today's day:");System.out.println("Enter the number of days elapsed since today:");Scanner sc = new Scanner(System.in);int today = sc.nextInt();int future= sc.nextInt();int x,y;String a,b="ERROR";x=future%7;y=today+x;switch(today){case 0:switch(y){case 0:case 7:b="Sunday";break;case 1:case 8:b="Monday";break;case 2:case 9:b="Tuesday";break;case 3:case 10:b="Wednesday";break;case 4:case 11:b="Thursday";break;case 5:case 12:b="Firday";break;case 6:b="Saturday";break;default:break;}a="Sunday";System.out.println("Today is "+a+" and the future day is "+b);break;case 1:switch(y){case 0:case 7:b="Sunday";break;case 1:case 8:b="Monday";break;case 2:case 9:b="Tuesday";break;case 3:case 10:b="Wednesday";break;case 4:case 11:b="Thursday";break;case 5:case 12:b="Firday";break;case 6:b="Saturday";break;default:break;}a="Monday";System.out.println("Today is "+a+" and the future day is "+b);break;case 2:switch(y){case 0:case 7:b="Sunday";break;case 1:case 8:b="Monday";break;case 2:case 9:b="Tuesday";break;case 3:case 10:b="Wednesday";break;case 4:case 11:b="Thursday";break;case 5:case 12:b="Firday";break;case 6:b="Saturday";break;default:break;}a="Tuesday";System.out.println("Today is "+a+" and the future day is "+b);break;case 3:switch(y){case 0:case 7:b="Sunday";break;case 1:case 8:b="Monday";break;case 2:case 9:b="Tuesday";break;case 3:case 10:b="Wednesday";break;case 4:case 11:b="Thursday";break;case 5:case 12:b="Firday";break;case 6:b="Saturday";break;default:break;}a="Wednesday";System.out.println("Today is "+a+" and the future day is "+b);break;case 4:switch(y){case 0:case 7:b="Sunday";break;case 1:case 8:b="Monday";break;case 2:case 9:b="Tuesday";break;case 3:case 10:b="Wednesday";break;case 4:case 11:b="Thursday";break;case 5:case 12:b="Firday";break;case 6:b="Saturday";break;default:break;}a="Thursday";System.out.println("Today is "+a+" and the future day is "+b);break;case 5:switch(y){case 0:case 7:b="Sunday";break;case 1:case 8:b="Monday";break;case 2:case 9:b="Tuesday";break;case 3:case 10:b="Wednesday";break;case 4:case 11:b="Thursday";break;case 5:case 12:b="Firday";break;case 6:b="Saturday";break;default:break;}a="Firday";System.out.println("Today is "+a+" and the future day is "+b);break;case 6:switch(y){case 0:case 7:b="Sunday";break;case 1:case 8:b="Monday";break;case 2:case 9:b="Tuesday";break;case 3:case 10:b="Wednesday";break;case 4:case 11:b="Thursday";break;case 5:case 12:b="Firday";break;case 6:b="Saturday";break;default:break;}a="Saturday";System.out.println("Today is "+a+" and the future day is "+b);break;}}/******end******/}

14.en_ 2017_ p1_014 Decimal to hex

Write a program that prompts the user to enter a decimal integer and displays its corresponding hexadecimal value.

Example:

Enter a decimal:

1235

The hex of this decimal is:4D3

    /******start******/import java.util.Scanner;public class Main {public static void main(String[]args){System.out.println("Enter a decimal:");Scanner sc = new Scanner(System.in);int a = sc.nextInt();System.out.println("The hex of this decimal is:"+Integer.toHexString(a).toUpperCase());}}/******end******/

exam平台Java试题阶段(一)相关推荐

  1. exam平台Java试题阶段(二)

    说明: 以下为过程化考试平台Java练习题,代码是自己写的,由于我的水平很有限,不免有不妥之处,欢迎指正赐教,谢谢! 1.en_ 2017_ sw_ p2_001 Define a stock cla ...

  2. java二级考试历年真题6_2018年3月计算机二级考试JAVA试题及答案(六)

    2018年计算机等级考试开考在即,小编在这里为考生们整理了2018年3月计算机二级考试JAVA试题及答案,希望能帮到大家,想了解更多资讯,请关注出国留学网的及时更新哦. 2018年3月计算机二级考试J ...

  3. 计算机等级考试java题型_计算机等级考试题库-2019二级java试题

    现在刷计算机等级考试题库是最佳时间,你刷了几套呢?收藏,还要记得复习好以下的二级java试题. 1.如果进栈序列为el.e2.e3.e4.e5,则可能的出栈序列是(). A.e3.el.e4.e2.e ...

  4. 二级java有题库吗_计算机等级考试题库:你get二级Java试题了吗?

    你复习了吗?
你做计算机等级考试题库了吗?你上机模拟了吗? 没有!没有!我什么都没有!突然一下子慌了有木有?感觉白交了几十块的报名费. 以下是考无忧小编为您准备的二级Java试题. 1). 下列关于f ...

  5. 华清远见-重庆中心-JAVA基础阶段技术总结

    系列文章目录 第一章 华清远见--重庆中心-JAVA基础阶段技术总结 第二章 文章目录 系列文章目录 文章目录 前言 一.关于java 1.发展历程 2.编程开发 3.java架构 4.java的特点 ...

  6. 华清远见—重庆中心——JAVA高级阶段知识点梳理

    华清远见-重庆中心--JAVA高级阶段知识点梳理 String字符串 String是一个类,属于数据类型中的引用类型.Java中所有使用""引起来的内容都是属于这个类的实例,称为字 ...

  7. java中属于高级事件的有,(盘点)计算机等级考试题库,二级Java试题

    在等剧更新的时间,赶紧进来刷刷题.复习一下,看剧.刷题,两不耽误,非常完美!以下是二级Java试题,赶紧看看吧! 文章推荐: 温馨提示: 考试想拿高分吗?更多计算机等级考试题库二级ms office试 ...

  8. java - 第一阶段总结

    java - 第一阶段总结 递归 递归:能不用就不用,因为效率极低 package over; //递归 public class Fi {public static void main(String ...

  9. 对接第三方平台JAVA接口问题推送和解决

    对接第三方平台JAVA接口问题推送和解决 参考文章: (1)对接第三方平台JAVA接口问题推送和解决 (2)https://www.cnblogs.com/CreateMyself/p/7295879 ...

最新文章

  1. LFCS 系列第二讲:如何安装和使用纯文本编辑器 vi/vim
  2. 算法---字符串去重
  3. poj Buy Tickets
  4. 【CyberSecurityLearning 附】Docker 初识
  5. python mysql写入速度加快_解决python写入mysql中datetime类型遇到的问题
  6. 戴尔全面进军一体机市场【我眼中的戴尔转型】
  7. Android 刷机脚本工具箱
  8. linux恢复群晖数据,群晖 篇二:群晖系统恢复手记
  9. 开发erp管理系统的好处
  10. 第6章 访问权限控制
  11. JavaScript实现富文本编辑器
  12. 1026 程序运行时间(C语言)
  13. 5D论文PMF及改进
  14. DataGear 自定义数据可视化图表
  15. 【渝粤教育】 国家开放大学2020年春季 1308外国文学专题 参考试题
  16. Hole_making基于特征加工
  17. AVFoundation学习记录
  18. 网络编程(基于socket接口技术的进程间通信)接上一篇文章补充
  19. wincc逻辑运算符_工控随笔_11_西门子_WinCC的VBS脚本_02_运算符
  20. 液晶12864显示字符

热门文章

  1. [CDQ分治与整体二分]个人对CDQ分治与整体二分的理解
  2. es拼音分词 大帅哥_SpringBoot集成Elasticsearch 进阶,实现中文、拼音分词,繁简体转换...
  3. docker创建容器相关命令【详细版】
  4. y700支持m2硬盘_别再浪费电脑的潜力,这些笔记本电脑都能升级NVMe固态硬盘
  5. STM32CubeMX SDIO SD卡 FATFS
  6. 纯虚函数 和 抽象类
  7. 概率论——随机变量的函数分布
  8. delphi 企业微信消息机器人_企业微信群消息机器人发送开源项目
  9. 2015年高教社杯全国大学生数学建模竞赛A题 “互联网+”时代的出租车资源配置
  10. USB Type-C简介