importjava.util.Scanner;publicclassTest2_1{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter a degree in Celsius:");doubleCelsius= input.nextDouble();doubleFahrenheit=(9.0/5)*Celsius+32;System.out.println(Celsius+"Celsius is"+" "+Fahrenheit+" "+"Fahrenheit");}}
2.2
importjava.util.Scanner;publicclassTest2_2{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);finaldouble PI =3.14;System.out.println("Enter the radius and length of a cyclinder:");double radius = input.nextDouble();double length = input.nextDouble();double area = radius * radius * PI;double volume = area * length;System.out.println("The area is"+" "+ area);System.out.println("The volume is"+" "+ volume);}}
2.3
importjava.util.Scanner;publicclassTest2_3{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter a value for feet");double feet = input.nextDouble();double meter = feet *0.305;System.out.println(feet +"feet is"+" "+ meter +"meter");}}
2.4
importjava.util.Scanner;publicclassTest2_4{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter a number in pounds:");double pounds = input.nextDouble();double kilograms = pounds *0.454;System.out.println(pounds +" "+"pounds is"+" "+ kilograms +" "+"kilograms");}}
2.5
importjava.util.Scanner;publicclassTest2_5{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the subtotal and a gratuity rate:");double subtotal = input.nextDouble();double rate = input.nextDouble();double gratuity = subtotal * rate *0.01;double total = subtotal + gratuity;System.out.println("The gratuity is"+" "+"$"+ gratuity +" "+"and total is"+" "+"$"+ total);}}
2.6
importjava.util.Scanner;publicclassTest2_6{publicstaticvoidmain(String[] args){System.out.println("Enter a number between 0 and 1000:");Scanner input =newScanner(System.in);int number = input.nextInt();int hundreds = number /100;int ones = number %10;int tens =(number /10)%10;int sum = hundreds + tens + ones;System.out.println("The sum of the digits is "+ sum);}}
2.7
importjava.util.Scanner;publicclassTest2_7{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the number of minutes:");int minutes = input.nextInt();int day= minutes /(60*24);int years = day /365;int days = day %365;System.out.println(minutes +" "+"minuters is approxiamtely"+" "+ years +" "+"and"+" "+ days +" "+"days");}}
2.8
在这里插入代码片
2.9
importjava.util.Scanner;publicclassTest2_9{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter v0,v1,and t:");double v0 = input.nextDouble();double v1 = input.nextDouble();double t = input.nextDouble();double a =(v1 - v0)/t;System.out.println("The average acceleration is"+" "+ a);}}
2.10
importjava.util.Scanner;publicclassTest2_10{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the amount of water in kilograms:");doubleM= input.nextDouble();System.out.println("Enter the initial temperature:");double temperature1 = input.nextDouble();System.out.println("Enter the final temperature:");double temperature2 = input.nextDouble();double energy =M*(temperature2 - temperature1)*4184;System.out.println("The enery needed is"+" "+ energy);}}
2.11
importjava.util.Scanner;publicclassTest2_11{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the number of years");int year = input.nextInt();double number =312032486;double t;
t =365*24*60*60;for(int i =1;i <= year;i++){
number = number +(t/7-t/13+t/45);}System.out.println("The population in"+" "+ year +" "+"years is"+" "+ number);}}
2.12
importjava.util.Scanner;publicclassTest2_12{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter speed and acceleration:");double speed = input.nextDouble();double acceleration = input.nextDouble();double length =(speed * speed)/(2* acceleration);System.out.println("The minimum length for this airplane is"+" "+ length);}}
2.13
importjava.util.Scanner;publicclassTest2_13{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the monthly saving amount:");double money = input.nextDouble();finaldouble t =0.00417;double sum =0.0;for(int i =1;i <=6;i++){
sum =(money + sum)*(1+ t);}System.out.println("After the six month, the account value is $"+ sum);}}
importjava.util.Scanner;publicclassTest2{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter x1 and y1");double x1 = input.nextDouble();double y1 = input.nextDouble();System.out.println("Enter x2 and y2");double x2 = input.nextDouble();double y2 = input.nextDouble();double t =(x2 - x1)*(x2 - x1)+(y2 - y1)*(y2 - y1);double distance =Math.pow(t,0.5);System.out.println("The distance between the tow points is"+" "+distance);}}
2.16
importjava.util.Scanner;publicclassTest2{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the length of the side:");double a = input.nextDouble();doubleS=(3*Math.pow(3,0.5)* a * a)/2;System.out.println("The area of the hexagon is"+" "+S);}}
2.17
importjava.util.Scanner;publicclassTest2{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the temperature inFahrenheit between -58°F and 41°F:");double t = input.nextDouble();System.out.println("Enter the wind speed (>= 2) in miles per hour:");double v = input.nextDouble();doubleT=35.74+0.6215* t -35.75*Math.pow(v,0.16)+0.4275* t *Math.pow(v,0.16);System.out.println("The wind chill index is"+" "+T);}}
2.18
publicclassTest2{publicstaticvoidmain(String[] args){System.out.println("a b pow(a,b)");for(int i =1;i<=5;i++){System.out.println(i +" "+(i+1)+" "+(int)Math.pow(i,i+1));}}}
2.19
importjava.util.Scanner;publicclassTest2{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the coordinates of three points separated by spaces:");double x1 = input.nextDouble();double y1 = input.nextDouble();double x2 = input.nextDouble();double y2 = input.nextDouble();double x3 = input.nextDouble();double y3 = input.nextDouble();double d1 =Math.pow((x1 - x2)*(x1 - x2)+(y1 - y2)*(y1 - y2),0.5);double d2 =Math.pow((x2 - x3)*(x2 - x3)+(y2 - y3)*(y2 - y3),0.5);double d3 =Math.pow((x1 - x3)*(x1 - x3)+(y1 - y3)*(y1 - y3),0.5);double s =(d1 + d2 +d3)/2;doubleS=Math.pow(s *(s - d1)*(s - d2)*(s - d3),0.5);System.out.println("The area of the trangle is "+" "+S);}}
importjava.util.Scanner;publicclassTest2{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter investment amount:");double investment = input.nextDouble();System.out.println("Enter annual interest rate in percentage:");double interest = input.nextDouble();System.out.println("Enter number of year:");int year = input.nextInt();double value = investment *Math.pow((1+ interest /1200),year *12);System.out.println("Future value is $"+ value);}}
2.22
在这里插入代码片
2.23
importjava.util.Scanner;publicclassTest2{publicstaticvoidmain(String[] args){Scanner input =newScanner(System.in);System.out.println("Enter the driving distance:");double distance = input.nextDouble();System.out.println("Enter miles per gallon:");double miles_per_gallon = input.nextDouble();System.out.println("Enter price per gallon:");double price_per_gallon = input.nextDouble();double money = distance / miles_per_gallon * price_per_gallon;System.out.println("The cost of driving is $"+" "+ money);}}