Showing posts with label Checking a Number. Show all posts
Showing posts with label Checking a Number. Show all posts

Wednesday, June 29, 2022

Checking a Number

 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");
   }
  }
}

ads vert

Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody

  Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody < table >      < thead >    ...