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

JAVA Object Oriented Programming: What are the results of the last two calculati

ID: 3591514 • Letter: J

Question

JAVA Object Oriented Programming:

What are the results of the last two calculations for z? Are they different? Explain why

                        int x = 2, y = 5;

                        double z;

                        z = (double) y / x;        

                        z = (double) (y / x);     

3) Write a system print line to print the following variables using printf

String name = “Frank”;

int id = 1234;

double netWorth = 500.36;

4) Write the code for this equation

              

            A=r2

5) Write a program that converts a military time string to hours and minutes. Ex “1730” “17 hours, 30 minutes”.

Explanation / Answer

The first z=2.5 as it will give float value of 5/2 = 2.5

The Second z= 2.0 as it will give float value of 2 which is equal to 2.0; as first 5/2 = 2 in integer value result then it will be converted to float.

3

public class Main

{

// main method begins execution of Java application

public static void main( String[] args )

{ String name = "Frank";

int id = 1234;

double netWorth = 500.36;

System.out.printf( "%s ", name );

//%s Displays a string

System.out.printf( "%d ", id );

//%d Displays a decimal (base 10 ) integer

System.out.printf( "%.2f ", netWorth );

//"%f for double and float

  

} // end method main

} // end c

4