The variable "num" holds an integer user input Write a conditional statement starting on line 9 that does the following:
-
If num is positive, print "__ is positive"
-
If num is negative, print "__ is negative"
Examples:
In: 5 5 is positive In: -2 -2 is negative In: 0 |
(no output for zero)
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
System.out.print("In:");
int num = inp.nextInt();
//DO NOT CHANGE ABOVE CODE! Write your code below
if(num>0) {
System.out.println(num+" is positive");
}
else if(num<0) {
System.out.println(num+" is negative");
}
}
}
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
017 - Conditional Statement Practice 3 (0) | 2019.11.28 |
---|---|
016 - Conditional Statement Practice 2 (0) | 2019.11.28 |
011 - String Methods Practice 2 (0) | 2019.11.26 |
010 - String Methods Practice 1 (0) | 2019.11.26 |
009 - String Methods - substring (0) | 2019.11.26 |