This exercise's objective is to help you understand variable declarations and their use in a Java program. You will also learn how to create both arithmetic and boolean expressions involving variables. One other objective of this lab is to familiarize you with the use of comments in Java.
Record the results you get after each exercise and have the TA check it by the end of lab. Also, show your working program to the TA.
/*
* Created on May 26, 2005
* Author: Mir Farooq Ali
* Purpose: Describe file here
* Programming Environment: Eclipse 3.1
*
* Programmer: farooq
*/
import java.util.Scanner;
public class LabExercise2 {
public static void main(String[] args) {
//Reading block starts here
int firstnum, secondnum;
Scanner inputScanner = new Scanner(System.in);
System.out.print("Enter the first number: ");
firstnum = inputScanner.nextInt();
System.out.print("Enter the second number: ");
secondnum = inputScanner.nextInt();
//Reading block ends here
// First block starts
// Perform some basic arithmetic operations here
System.out.println("(firstnum + secondnum) = " +
(firstnum + secondnum));
System.out.println("(firstnum - secondnum) = " +
(firstnum - secondnum));
System.out.println("(firstnum * secondnum) = " +
(firstnum * secondnum));
System.out.println("(firstnum / secondnum) = " +
(firstnum / secondnum));
System.out.println("(firstnum % secondnum) = " +
(firstnum % secondnum)); // First block ends
/* // Second block starts
boolean x, y, z;
x = (firstnum > secondnum); // test if firstnum is greater secondnum
System.out.println("x = " + x);
y = (firstnum <= secondnum); // test if firstnum is less than or equal to secondnum
System.out.println("y = " + y);
//z = (); // test for equality of firstnum with secondnum
//System.out.println("z = " + z);
// z = (); // test if firstnum is greater than or equal to secondnum
// System.out.println("z = " + z);
*/ // Second block ends
/* // Third block starts
double p, q, r, s, t, val;
p = 20.0;
q = 10.0;
r = 7.0;
s = 13.0;
t = 17.0;
// val = // Complete this statement
System.out.println("value = " + val);
*/ // Third block ends
}
}
Complete the statement for the variable val based on the equation shown above. Write this down on a sheet of paper. With the values of p, q, r, s and t shown above, the variable val's value should be 4.0.