Checking a Number
Problem Statement
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) {
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
if (num>0)
{
num=1;
}else if (num<0)
{
num=-1;
}else {
num=0;
}
switch(num){
case 1:
System.out.print("Positive");
break;
case -1:
System.out.print("Negative");
break;
default:
System.out.print("Zero");
}
}
}