Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

remove the fhrst character! The last Chalacte R2.22 Write a program that prints

ID: 3585131 • Letter: R

Question

remove the fhrst character! The last Chalacte R2.22 Write a program that prints the values 31000 1000 1000 3.0 1000 1000 1000 Explain the results. R2.23 This chapter contains a number of recommendations regarding variables and con- stants that make programs easier to read and maintain. Briefly summarize these recommendations. ROGRAMMING EXERCISES - P2.1 Write a program that displays the dimensions of a letter-size (8.5 x 11 inches) sheet of paper in millimeters. There are 25.4 millimeters per inch. Use constants and com- ments in your program. P2.2 Write a program that computes and displays the perimeter of a - P2.3 Write a program that reads a number and displays the square, cube, and fourth P2.4 Write a program that prompts the user for two integers and then prints inches) sheet of paper and the length of its diagonal. letter-size (8.5 × 11 power. Use the Math.pow method only for the fourth power. . The sunm The difference

Explanation / Answer

2.1 //code below

import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       double mtoi=25.4; //conversion value
       System.out.println("Dimensions of letter : "+8.5*mtoi+"mmX"+11*mtoi+"mm"); //display the dimensions
   }
}

2.3 //code below

import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       double a;
       Scanner sc=new Scanner(System.in); //scanner class object
       a=sc.nextDouble(); //input a double from user
       System.out.println("Square : "+a*a+" Cube : "+a*a*a+" Fourth power : "+Math.pow(a,4)); //display the square, cube and 4th power
   }
}

2.8 //code given below

import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       double a,b;
       System.out.println("Enter length and breadth : ");
       Scanner sc=new Scanner(System.in); //scanner class object
       a=sc.nextDouble(); //input a double from user
       b=sc.nextDouble(); //input a double from user
       System.out.println("Perimeter : "+2*(a+b)); //display perimeter
       System.out.println("nArea : "+a*b);   //display area
       System.out.println("Diagonal : "+Math.sqrt(a*a+b*b)); //display diagonal
   }
}

2.30 //code given below

import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       double r;
       System.out.println("Enter R : ");
       Scanner sc=new Scanner(System.in); //scanner class object
       r=sc.nextDouble(); //input a double from user
       double b=3969,r1=1075,t1=85+273; //intiaise the constants
       double t=b*t1/(t1*Math.log(r/r1)+b)-273; //use formula to find t
       System.out.println("Temperature, in `C : "+t); //display t in celcius scale
   }
}