Computer Science, asked by Anonymous, 3 days ago

WRITE A PROGRAM IN JAVA TO ENTER ANY NUMBER AND PRINT NUMBER IS POSITIVE:-​

Answers

Answered by BrainlyProgrammer
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 jangirjayesh31
3

Explanation:

  1. import java.util.Scanner;
  2. public class Postive_Negative.
  3. {
  4. public static void main(String[] args)
  5. {
  6. int n;
  7. Scanner s = new Scanner(System. in);
  8. System. out. print("Enter the number you want to check:");

Similar questions