Question
Part 2: Create a NEW Java application Lab1Part2. Do not reuse the Lab1Part1 program. In Lab1Part2, enter the code below. Remember, if you create this
Part 2: Create a NEW Java application Lab1Part2. Do not reuse the Lab1Part1 program. In Lab1Part2, enter the code below. Remember, if you create this in NetBeans, be careful about cutting and pasting. Things like quotation marks can mess up when copied. Also note that when you start a new program, i.e. make a new Java application, in NetBeans that you will need to set a new Main Project before you can run your new application. Go to the Run menu, choose Set Main Project, then select the name of the new application you just created.
public class Lab1Part2
{
public static void main(String[] args)
{
int num1 = 48; // num1 & num2 are variables
int num2; // that can hold INTeger values
System.out.println("Printing variable values");
System.out.println("Num1 = "+num1);
num2 = 6;
System.out.println("Num2 = "+num2);
System.out.println("Product of num1 & num2 = "+ (num1 * num2) );
System.out.println("Sum of num1 & num2 = "+ (num1 + num2) );
System.out.println(); // prints a blank line
System.out.println("Num1 = "+num1+" Num2 = "+num2);
num1 = num1 - (num2 * 3);
double num3 = num2; // num3 will hold floating point values
System.out.println(" Num1 = "+num1+" Num2 = "+num2 + " Num3 = "+num3);
num3 = num3 / 3 + (num1/num3)/2;
num2 = num2 / 3 + (num1/num2)/2;
System.out.println("New value of num1 is "+num1);
System.out.println("Final value of num2 = "+num2);
System.out.println("Value of num3 is "+num3 + " ");
System.out.println("Adding num1 and num2 (version 1) "+ num1 + num2 );
System.out.println("Adding num1 and num2 (version 2) "+ (num1 + num2) );
System.out.println("Adding num1 and num3 (version 3) "+ (num1 + num3) );
System.out.println("Adding num1 and num3 (version 4) "+ num1 + num3 );
}
}
2.a) If you execute this program, what will be printed in the output window? Show all output in your answer. (2 pts)
2.b) What is the name of the operation = in the Java programming language? HINT: It isnt equals. (2 pts)
2.c) What is being printed in second to the last line of output from the part of the println command that has + (num1 + num3) , i.e. what specific output is produced from just this part of the println command? (2 pts)
2.d) What is being printed in the second to last line of output from + num1 + num3 ? (2 pts)
2.e) What causes these two outputs to be different in your opinion? Tell what is different in the println statements and tell how this difference affects what is printed out. (3 pts)
2.f) What does the Java command System.out.println do? (2 pts)
2.g) Tell how many variables are declared in this program, give the names of the variables and give the data types of the variables. (4 pts)
2.h) Tell how many variables are declared in this program, give the names of the variables and give the data types of the variables. (4 pts)
2.i) There are two different things in this program that cause a blank line to be printed. List both of them. (2 pts)
2.j) Show the steps of the arithmetic that is being done in each of the Java statements below (from the code). The first step of the first line is done for you and the second step is started. (6 pts)
num3 = num3 / 3 + (num1/num3) / 2; // statement 1
| | | |
| | (num1/num3) is 30/6.0 which gives 5.0 [STEP 1]
| | |
| num3 / 3 is ___________________________________________
| |
| ________________________________________
|
________________________________
num2 = num2 / 3 + (num1/num2)/2; // statement 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started