Skip to content

Write a program to check whether a number is positive, negative or zero using switch case.

Notifications You must be signed in to change notification settings

nitish4445/Checking-a-Number

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Checking-a-Number

Write a program to check whether a number is positive, negative or zero using switch case. import java.io.; // for handling input/output import java.util.; // contains Collections framework

// don't change the name of this class // you can add inner classes if needed

class Main { public static void main (String[] args) { // Your code here Scanner sc=new Scanner(System.in); int x= sc.nextInt(); int numCheck = x > 0 ? 1 : x == 0 ? 0: -1; switch(numCheck) { case 1: System.out.println("Positive"); break; case -1: System.out.println("Negative"); break; case 0: System.out.println("Zero"); break; } } }

About

Write a program to check whether a number is positive, negative or zero using switch case.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published