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 { ...
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...
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")
1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...
I am in an entry-level Java class and need assistance solving questions 20-25 for a homework assignment. Any help is appreciated. Thank you. Q20 Read the code and answer the question 6 Points Read each of the following code snippets and determine if they are equivalent. I.e. they produce the same output. Q20.1 Are these snippets equivalent? 2 Points Snippet 1: int i=0; while (i<10) System.cut.print(i); i++; 1 Snippet 2: for(int i-0; i<10; i++) System.out.print(i); } Yes O No Q20.2...
Please answer both questions. Thanks Question 26 (1 point) What is the output generated by the code segment below, assuming that data is a Scanner object used to read the following text: As the world turns. data.useDelimiter(" "); int count = 0; while (data.hasNext()) { char input data.next().charAt(0); if (! Character.isLetter (input)) { count++; System.out.println (count); A/ Question 27 (1 point) Assuming that the user provides 114 as input, what is the output of the following code snippet? Please make...