Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java code If-else statement: Fix errors. import java.util.Scanner; public class

ID: 3737956 • Letter: J

Question

java code

If-else statement: Fix errors.

import java.util.Scanner;

public class ConvertNegative {
public static void main (String [] args) {
int userNum = 0;

/* Your solution goes here */

return;
}
}

Re type the code and fix any errors. The code should convert negative numbers to 0.
  if (userNum >= 0)     System.out.println("Non-negative");  else     System.out.println("Negative; converting to 0");     userNum = 0;  System.out.format("Final: %d", userNum);  System.out.println(""); 

import java.util.Scanner;

public class ConvertNegative {
public static void main (String [] args) {
int userNum = 0;

/* Your solution goes here */

return;
}
}

Explanation / Answer

ConvertNegative.java

import java.util.Scanner;

public class ConvertNegative {

public static void main (String [] args) {

int userNum = 0;

/* Your solution goes here */

if (userNum > 0)

System.out.println("Non-negative");

else {

System.out.println("Negative; converting to 0");

userNum = 0;

}

System.out.format("Final: %d", userNum);

System.out.println("");

return;

}

}

Output:

Negative; converting to 0
Final: 0