exam平台Java试题阶段(一)

这是一系列Java基础练习题,包括温度转换、体积计算、单位换算、小费计算等实际应用问题,旨在提升Java编程技能。题目涵盖数学、物理等多个领域,适合初学者进行实践练习。
摘要由CSDN通过智能技术生成

说明:

以下为过程化考试平台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&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值