2.1
Public class Test { publicstaticvoid main (string[] args) { new Scanner (system.in); Double F, c; = input.nextdouble (); = (9.0/5) *c+32; System.out.println (f); }}
2.2
Public classTest { Public Static voidMain (string[] args) {DoubleR, H; Final DoublePI = 3.1415925; System.out.println ("Enter the radius and length of a cylinder:"); Scanner input=NewScanner (system.in); R=input.nextdouble (); H=input.nextdouble (); System.out.println ("The area is" + pi*r*R); System.out.println ("The volume is" + pi*r*r*h); }}
2.3
Public class Test { publicstaticvoid main (string[] args) { double F, m; New Scanner (system.in); System.out.println ("Enter a value for feet:"); = input.nextdouble (); + "feet is" + 0.305 *f + "meters");} }
2.4
Public class Test { publicstaticvoid main (string[] args) { double p, K; New Scanner (system.in); System.out.println ("Enter a number in pounds:"); = input.nextdouble (); + "pounds is" + 0.454 * p + "kilograms");} }
2.6
Public classTest { Public Static voidMain (string[] args) {intn, sum, T; Scanner input=NewScanner (system.in); System.out.println ("Enter a number between 0 and 1000:"); N=Input.nextint (); Sum= 0; T= n% 10; while(T! = 0) {sum+=T; N/= 10; T= n% 10; } System.out.println ("The sum of the digits is" +sum); }}
2.7
Public classTest { Public Static voidMain (string[] args) {intm = 0; intyears, days, t; System.out.println ("Enter the number of minutes:"); Scanner input=NewScanner (system.in); M=Input.nextint (); T= (M/60)/24; Years= t/365; days= t% 365; System.out.println (M+ "Minutes is approximately" + years + "years and" + Days + "days."); }}
2.8
Public classTest { Public Static voidMain (string[] args) {intN; CharC; Scanner input=NewScanner (system.in); System.out.print ("Enter An ASCII code:"); N=Input.nextint (); C= (Char) n; System.out.println ("The character for ASCII code" + N + "is" +c); }}
2.11
Public classTest { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); System.out.println ("Enter Employee's name:"); String name=Input.next (); System.out.println ("Enter number of hours worked in a week:"); floatHours =input.nextfloat (); System.out.println ("Enter Hourly pay rate:"); floatPayRate =input.nextfloat (); System.out.println ("Enter Federal Withholding rate:"); floatFTWR =input.nextfloat (); System.out.println ("Enter state Tax withholding rate:"); floatSTWR =input.nextfloat (); System.out.println ("Employee Name" +name); System.out.println ("Hours worked" +hours); System.out.println ("Pay: $" +payrate); System.out.println ("Gross Pay: $" + hours *payrate); System.out.println ("Deductions:"); System.out.println ("Federal Withholding (" + ftwr * + "%): $" + payrate *FTWR); System.out.println ("State Withholding (" + stwr * + "%): $" + payrate *STWR); System.out.println ("Total Deduction: $" + payrate * (FTWR +STWR); }}
2.12
Public class Test { publicstaticvoid main (string[] args) { new Scanner (system.in); System.out.println ("Enter balance and interest rate (e.g., 3 for 3%):"); double balance = input.nextdouble (); double rate = input.nextdouble (); System.out.printf ("The interest is%.4f", Balance * (rate/1200));} }
2.13
Public classTest { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); //System.out.println ("Enter balance and interest rate (e.g., 3 for 3%):");System.out.print ("Enter Investment Amount:"); DoubleInvestmount =input.nextdouble (); System.out.print ("Enter Monthly interest Rate:"); DoubleRate =input.nextdouble (); System.out.print ("Enter Number of years:"); intYear =Input.nextint (); Doubles = Investmount * Math.pow ((1 + rate/100), (Year * 12)); System.out.println ("Accumulated value is" +s); }}
2.14
public class Test { public static void main (string[] args) {Scanne R input = new Scanner (system.in); System.out.print ( "Enter weigth in Pounds:" float weigth = Input.nextfloat (); System.out.print ( "Enter heigth in Inches:" float height = Input.nextfloat (); System.out.println ( BMI is) + 0.45359237 * WEIGTH/MATH.POW (Height * 0.0254, 2)); }}
2.15
Public classTest { Public Static voidMain (string[] args) {DoubleT, S; S= T = 0; Scanner input=NewScanner (system.in); for(inti = 0; I < 6; i++) {s= (+ + t) * (1 + 0.00417); T=s; } System.out.println ("After six months, result is:" +s); }}
2.16
Public classTest { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); System.out.print ("Enter The amount of water in kilogram:" ); Doublem =input.nextdouble (); System.out.print ("Enter The initial temperature:" ); Doubleit =input.nextdouble (); System.out.print ("Enter The final temperature:" ); DoubleFT =input.nextdouble (); System.out.println ("The energy needed is" + M * (ft-it) * 4184); }}
2.17
Public classTest { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); System.out.print ("Enter the temperature in Fahrenheit:" ); Doublef =input.nextdouble (); System.out.print ("Enter the Wind miles per hour:"); DoubleSpeed =input.nextdouble (); System.out.println ("The wind chill Index are" + (35.74 + 0.6215 * f-35.75 * MATH.POW (speed, 0.16) + 0.427 * f * MATH.POW (speed, 0.16))); }}
2.18
Public classTest { Public Static voidprint () {System.out.print (" "); } Public Static voidMain (string[] args) {System.out.println ("A B Pow (A, b)"); for(inti = 1; I < 6; i++) {System.out.print (i); Print (); System.out.print (i+ 1); Print (); System.out.println ((int) Math.pow (i, I +1)); } }}
Programming exercises in the 2nd Chapter of Java language programming