Question 4 (1 point)
Translate this Python statement to Java:
print(n, end=' ')
Question 4 options:
|
a. |
System.out.print(n) |
|
b. |
System.out.print(n + " "); |
|
c. |
System.out.println(n); |
|
d. |
System.println(n + " "); |
Question 5 (1 point)
What is the output of this code fragment?
int count = 0;
for(int n = 3; n <= 10; n += 2) {
count++;
}
System.out.println(count);
Question 5 options:
|
a. |
2 |
|
b. |
3 |
|
c. |
4 |
|
d. |
10 |
Answer:--------
4. b. System.out.println (n + " ");
5. c. 4 because count will be increased by 1 for n = 3 ( count = 1 ) , again it will be increased by 1 for n = 5 ( count = 2 ) , again it will increased by 1 for n = 7 ( count = 3 ) , again it will increased by 1 for n = 9 ( count = 4 ). And for n = 11 it will exit from for loop and will print count = 4.
Question 4 (1 point) Translate this Python statement to Java: print(n, end=' ') Question 4 options:...
Java Questions When creating a for loop, which statement will correctly initialize more than one variable? a. for a=1, b=2 c. for(a=1, b=2) b. for(a=1; b=2) d. for(a = 1&& b = 2) A method employee() is returning a double value. Which of the following is the correct way of defining this method? public double employee() c. public int employee() public double employee(int t) d. public void employee() The ____ statement is useful when you need to test a...
Question 15 (1 point) What does this program print? Please make sure your spacing is exact. public class Test { System.out.print("39 + 3"); System.out.println(39 + 3); } 1 A/ Question 5 (1 point) Consider a file called input.txt that has the following 4 lines: Trace the program when it is 89 lines 78.5 is average. Isn't it? What would be the value of count after the following code snippet executes? Scanner in = new Scanner (new File("input.txt")); int count 0;...
Goal: Translate this Python script into Java: magic8ball.py Deliverable: Magic8Ball.java Grading Breakdown: Functionality: 35; Source code comments: 5; Indentation: 5; Properly Submitted: 5. Example: Here is a Java class that simulates the roll of a single die: import java.util.Random; public class DiceRoll { public static void main(String[ ] args) { Random r = new Random( ); int roll1 = r.nextInt(6) + 1; int roll2 = r.nextInt(6) + 1; System.out.println("Sum of rolls:" + (roll1 + roll2)); } } Here is the...
Please try to explain the answers as well. It will be highly appreciated. Output of the following expression: 5 * 4 % 2 = ? Output of a loop: Example: What will be the output of the Java code (Assume all variables are properly declared.) num = 10; while (num <= 32) num = num + 5; System.out.println(num); What will be the output of the Java code (Assume all variables are properly declared.) public class test { ...
this needs to be in Java 1) What displays from this code segment when n=6? for (int i = 0; i < n; i++) System.out.print (i + “ ”); System.out.println (); for (int j=n; j > 0; j--) System.out.print ( j + “ “); 2) What displays from this code segment when n=6? for (int i = 0; i < n; i++) System.out.print (i + “ ”); System.out.println (); for (int j=n; j > 0; j--) System.out.print ( j +...
Please answer both questions thank you.
Question 39 (1 point) Translate the following conditions to Java, where x is an integer and s is a string. 1. x >= 6 2. x < 0 s is "Day" 3. S = "Day" x is at least 6 4. X == -7 DODO x is at most 6 5. x = -7 x is - 7 6. s.equals("Day") 7. x <= 6 x is not 27 8. X >O x is positive...
Given the following Java code fragment, what is output? int a, b; String c, d, e; String x = new String(“I LOVE”); String y = “java!”; a = x.length( ); System.out.println(“1) “ + a); b = y.length( ); System.out.println(“2) “ + b); c = y.toUpperCase( ); System.out.println(“3) “ + c); d = x.toLowerCase( ); System.out.println(“4) “ + d); e = x.concat(y); System.out.println(“5) “ + e);
Question 41 Which of the following is NOT a valid assignment statement? A. x = 55; B. 55 = x; C. x += 3; D. x = 56 + y; Question 42 What is the result of 45 / 4? A. 11.25 B. 10 C. 12 D. 11 Question 43 What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0");...
1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...
Python Modify the following code by only adding end and sep options to the existing print commands to get the output A.B;C:E-- Here is the code to modify: print("A","B") print("C") print("E")