说明:
以下为过程化考试平台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&#