Create two integers var1 200 var2 35 Display the integers c

Create two integers var1 = 200, var2= 35. Display the integers. calculate the value var1/var2 and display the result (see example on page 23). Notice what you get for answer (answer should be integer)

Create one integer var1 = 10, and one double var2= 10.0 . divide each by 4 and display the results. Notice the difference in the answers. (see example page 25)

write a program to convert 200 liters to gallons ( google the conversion factor from liters to gallons). see example page 27. Note: make all variables double type.

write a program creating two integers a=5, b= 10. Write three if statements.

if a== b print the values of a and b and the statement a and b are equal

if a> b print the values of a and b and the statement a is greater than b

if a< b print the values of a and b and the statement a is less than b

for loop- Write a program to print the numbers from 1 to 20

**implement in java do everything in one class

Solution


//JavaClass.java


import java.util.Scanner;

public class JavaClass
{

public static void main(String[] args)
{
        // Create two integers var1 = 200, var2= 35. Display the integers. calculate the value var1/var2 and display the result
        int var1 = 200;
        int var2 = 35;
        // since int/int division is integer, thus var1/4 will be integer
        System.out.println(var1 + \"/\" + var2 + \" = \" + var1/var2);

        System.out.println(\"\");

        // Create one integer var1 = 10, and one double var2= 10.0 . divide each by 4 and display the results
        var1 = 10;
        double var3 = 10.0;
        // since int/int division is integer, thus var1/4 will be integer
        System.out.println(var1 + \"/4 = \" + var1/4);
        // since double/int division is double, thus var3/4 will be double
        System.out.println(var3 + \"/4 = \" + var3/4);

        // program to convert 200 liters to gallons
        double conversionFactor = 0.26417205235815;
        System.out.println(\"\ 200 liters is \" + (200*conversionFactor) + \" gallons\ \");

        // program creating two integers a=5, b= 10. and three if statements.
        int a = 5, b = 10;
        if(a == b)
            System.out.println(a + \" is equal to \" + b);
else if(a > b)
            System.out.println(a + \" is greater than \" + b);
    else if(a < b)
            System.out.println(a + \" is less than \" + b);

}

}

/*
Output:

200/35 = 5

10/4 = 2
10.0/4 = 2.5

200 liters is 52.83441047163 gallons

5 is less than 10

*/

Create two integers var1 = 200, var2= 35. Display the integers. calculate the value var1/var2 and display the result (see example on page 23). Notice what you g
Create two integers var1 = 200, var2= 35. Display the integers. calculate the value var1/var2 and display the result (see example on page 23). Notice what you g

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site