WRITE A PROGRAM IN JAVA TO ENTER ANY NUMBER AND PRINT NUMBER IS POSITIVE:-
Answers
Answered by
4
Answer:
import java.util.Scanner;
class Num{
public static void main (String ar[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
System.out.println(n>=0?"Positive":"Negative");
//Zero is taken as a positive number.
}
}
Explanation:
- The above program creates an object of Scanner class which is included using import statement
- It then go on to accept an input from the user.
- Then, it checks if the number is positive (greater than or equal to zero) yes? it displays "Positive" otherwise "Negative".
Extra:-
- Ternary operator is also known as Conditional Assignment Statement.
- Syntax:
variable= (Condition)? statement_1: statement_2;
Answered by
3
Explanation:
- import java.util.Scanner;
- public class Postive_Negative.
- {
- public static void main(String[] args)
- {
- int n;
- Scanner s = new Scanner(System. in);
- System. out. print("Enter the number you want to check:");
Similar questions