首页 > 编程 > Java > 正文

JAVA语言程序设计-基础篇课后习题2.1--2.17

2019-11-06 07:34:53
字体:
来源:转载
供稿:网友
package part02;import java.util.Scanner;public class test2_1 { public static double fahernheit(double degree) { double fa; fa = degree*(9/5)+32; return fa; } public static void main(String[] args){ double degree; Scanner input = new Scanner(System.in); System.out.PRintln("enter aa degree in celsius : "); degree = input.nextDouble(); System.out.println(degree + "Celsius is " + fahernheit(degree) + " Fahrenheit"); }}------------------------------------package part02;import java.util.Scanner;public class Test2_2 { static void areaAndVolume(double radius,double length) { 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); } public static void main(String[] args) { double radius,length; Scanner input = new Scanner(System.in); System.out.println("Enter the radius an length of a cyliner : "); radius = input.nextDouble(); length = input.nextDouble(); areaAndVolume(radius,length); }}------------------------------------package part02;import java.util.Scanner;public class Test2_3 { static void feetToMeters(double feet){ double meters; meters = 0.305*feet; System.out.println(feet + " feet is " + meters + " meters"); } public static void main(String[] args) { double feet; Scanner input = new Scanner(System.in); System.out.println("Enter a value for feet"); feet = input.nextDouble(); feetToMeters(feet); }}------------------------------package part02;import java.util.Scanner;public class Test2_4 { static void poundToKil(double pound){ double kil; kil = pound*0.454; System.out.println(pound + " pounds is " + kil + " lilograms"); } public static void main(String[] args) { Scanner input = new Scanner(System.in); double pound; System.out.println("Enter a number in pounds :"); pound = input.nextDouble(); poundToKil(pound); }}------------------------------------------------package part02;import java.util.Scanner;public class Test2_5 { static void gra(double subtotal,double rate) { double gra; gra = subtotal*rate/100; System.out.println("The gratuty is &" + gra + " and total is $" + (subtotal + gra)); } public static void main(String[] args) { double subtotal,rate; Scanner input = new Scanner(System.in); System.out.println("Enter the subtotal and a gratuity rate :"); subtotal = input.nextDouble(); rate = input.nextDouble(); gra(subtotal,rate); } }--------------------------------------------package part02;import java.util.Scanner;public class Test2_6 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num,digits = 0; System.out.println("Enter a number between 0 and 1000 :"); num = input.nextInt(); if(num>=0&&num<=1000) { if(num>=0&&num<10) { digits = num; } else if(num>=10&&num<100) { digits = num%10 + num/10; } else if(num>=100&&num<1000) { digits = num/100 + (num/10)%10 + (num%100)%10; } else { digits = 1; } } else { System.out.println("input error"); } System.out.println("the sum of the digits is " + digits); }}--------------------------------package part02;import java.util.Scanner;public class Test2_7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); long minutes; int year,day; System.out.println("enter the number of the minutes :"); minutes = input.nextLong(); year = (int)minutes/(60*24*365); day = (int)minutes%(60*24*365)/(60*24); System.out.println(minutes + " minutes is app " + year + " years and " + day + " days"); }}-------------------------------------------------package part02;import java.util.Scanner;public class Test2_9 { public static void main(String[] args){ double t; double v1,v2,a; Scanner input = new Scanner(System.in); System.out.println(" Enter v1 v2 and t :"); v1 = input.nextDouble(); v2 = input.nextDouble(); t = input.nextDouble(); a = (v2 - v1)/t; System.out.println("the average acceleration is :" + a); }}-----------------------------------------------package part02;public class Test2_10 { public static void main(String[] args){ System.out.println("公式计算,和前几题差不多"); }}---------------------------------------------------package part02;import java.util.Scanner;public class Test2_13 { public static void main(String[] args) { double crrent; Scanner input = new Scanner(System.in); System.out.println(" enter the monthly saving amount : "); crrent = input.nextDouble(); int month=1; while(month<=6) { crrent = (1+0.00417)*crrent; month++; if(month<=6) crrent += 100; } System.out.println(" After the sixth month, the account is &" + crrent); }}-----------------------------------------------------------package part02;import java.util.Scanner;public class Test2_14 { public static void main(String[] args){ Scanner input = new Scanner(System.in); double pounds,inches; System.out.println("enter weight in pounds :"); pounds = input.nextDouble(); System.out.println("enter high in inches :"); inches = input.nextDouble(); System.out.println("BMI is " + (pounds*0.45359237)/(inches*0.0254));//待续 }}-------------------------------------------------package part02;import java.util.Scanner;public class Test2_15 { public static void main(String[] args){ double x1,y1,x2,y2; double d; Scanner input = new Scanner(System.in); System.out.println("Enter x1 and y1 :"); x1 = input.nextDouble(); y1 = input.nextDouble(); System.out.println("Enter x2 and y2 :"); x2 = input.nextDouble(); y2 = input.nextDouble(); d = Math.pow(Math.pow(x1-x2, 2)+Math.pow(y1-y2, 2),0.5); System.out.println("The distance between the two points is " + d); }}----------------------------------------------------------------package part02;import java.util.Scanner;public class Test2_17 { public static void main(String[] args) { double temperature,wind; Scanner input = new Scanner(System.in); System.out.println("Enter tje temperature in Fahrenheit between -58 and 41 F"); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表