Question 1. Write a Java program to get a number from the user and print whether it is positive or negative.
Test Data
Input number: 35
Expected Output :
Number is positive
Ans:
package HelloWorld;
import java.util.Scanner;
public class LearningJava {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
if (n >= 0 ){
System.out.print("Positive");
}
else {
System.out.print("Negative");
}
}
}
Comments
Post a Comment