Docsity

Quiz 1 with Solution - Java Programming | COP 2250, Quizzes of Javascript programming

Toggle sidebar
bg1
1. [1 pt] Describe steps to create a simple HelloWorld application using Netbeans.
Open Netbeans -> File -> New Project -> Choose “Java ” categories and “Java
Application” -> Give Project Name and Location -> Add a new class named
HelloWorld
2. [1 pt] Name at least two of the following.
a. Course Website http://www.cs.fiu.edu/~ezeng001/cop2250
b. Instructor email [email protected]
c. Instructor phone (305) 348 -6250
d. Instructor office ECS 254
e. Course office hours M/W 11:00 - 12:00 & 13:30 - 15:00
3. [2 pts] Add the following lines to the main method:
int x=6;
double y=8.634;
y=x+y;
System.out.println("y= " + y);
y=y%3;
System.out.println("y= " + y);
int z=(int) y;
System.out.println("z= " + z);
What is the output of the program?
y= 14.634
y= 2.6340000000000003
z= 2
4. [2 pts] Add the following lines to the end of the main method body in problem 3.
System.out.println("x/y = " + x/y);
y = z;
System.out.println("y= " + y);
System.out.println("x/z = " + x/z);
System.out.println("x/y = " + x/y);
What is printed by the program?
x/y = 2.2779043280182227
y= 2.0
x/z = 3
x/y = 3.0
Why outputs are different for two “x/y=”?
Values of y in x/y are different: the first is 2.634 and the second 2.0
Why the last two outputs are different?
x/z is division between two integers and x/y is division between double
variables (x will be promoted to double variable before division operation)

Partial preview of the text

Download Quiz 1 with Solution - Java Programming | COP 2250 and more Quizzes Javascript programming in PDF only on Docsity!

  1. [1 pt] Describe steps to create a simple HelloWorld application using Netbeans. Open Netbeans -> File -> New Project -> Choose “Java ” categories and “Java Application” -> Give Project Name and Location -> Add a new class named HelloWorld
  2. [1 pt] Name at least two of the following. a. Course Website http://www.cs.fiu.edu/~ezeng001/cop b. Instructor email [email protected] c. Instructor phone (305) 348 - d. Instructor office ECS 254 e. Course office hours M/W 11:00 - 12:00 & 13:30 - 15:
  3. [2 pts] Add the following lines to the main method: int x=6; double y=8.634; y=x+y; System.out.println("y= " + y); y=y%3; System.out.println("y= " + y); int z=(int) y; System.out.println("z= " + z); What is the output of the program? y= 14. y= 2. z= 2
  4. [2 pts] Add the following lines to the end of the main method body in problem 3. System.out.println("x/y = " + x/y); y = z; System.out.println("y= " + y); System.out.println("x/z = " + x/z); System.out.println("x/y = " + x/y); What is printed by the program? x/y = 2. y= 2. x/z = 3 x/y = 3. Why outputs are different for two “x/y=”? Values of y in x/y are different: the first is 2.634 and the second 2. Why the last two outputs are different? x/z is division between two integers and x/y is division between double variables (x will be promoted to double variable before division operation)