Spot the erros in the following java code and correct to match the instructions: Print "userNum1 is negative." if userNum1 is less than 0. End with newline. Assign userNum2 with 4 if userNum2 is greater than 15. Otherwise, print "userNum2 is less than or equal to 15.". End with newline.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter6: Looping
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question
100%

Spot the erros in the following java code and correct to match the instructions:

Print "userNum1 is negative." if userNum1 is less than 0. End with newline.

Assign userNum2 with 4 if userNum2 is greater than 15. Otherwise, print "userNum2 is less than or equal to 15.". End with newline.

 

Print "userNum1 is negative." if userNum1 is less than 0. End with newline.
Assign userNum2 with 4 if userNum2 is greater than 15. Otherwise, print "userNum2 is less than or equal to 15.". End with
newline.
1 import java.util.Scanner;
2 public class UserNums {
3
public static void main (String [) args) {
int userNum1;
int userNum2;
4
7
Scanner input = new Scanner(System.in);
userNum1 = input.nextInt();
userNum2 = input.nextInt();
8
9
10
11
if (userNum1 < 0) {
System.out.println("userNum1 is negative.");
}
else if (userNum2 > 15) {
userNum2 = 4;
}
else if (userNum2 < 15) {
System.out.println("userNum2 is less than or equal to 15.");
12
13
14
15
16
17
18
19
20
21
System.out.println("userNum2 is " + userNum2);
}
22
23
24
25 }
Transcribed Image Text:Print "userNum1 is negative." if userNum1 is less than 0. End with newline. Assign userNum2 with 4 if userNum2 is greater than 15. Otherwise, print "userNum2 is less than or equal to 15.". End with newline. 1 import java.util.Scanner; 2 public class UserNums { 3 public static void main (String [) args) { int userNum1; int userNum2; 4 7 Scanner input = new Scanner(System.in); userNum1 = input.nextInt(); userNum2 = input.nextInt(); 8 9 10 11 if (userNum1 < 0) { System.out.println("userNum1 is negative."); } else if (userNum2 > 15) { userNum2 = 4; } else if (userNum2 < 15) { System.out.println("userNum2 is less than or equal to 15."); 12 13 14 15 16 17 18 19 20 21 System.out.println("userNum2 is " + userNum2); } 22 23 24 25 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning