Lec :11 | JAVA

     

LEC:11

Switch Cases in JAVA



      


Source Code:
package lec_5;

import java.util.*;

public class Lec_5 {

    public static void main(String[] args) {
//1 add
//2 subtarction
//3 multiplication
//4 division

//    switch(ch) 
//    {
//case 1
//add();
//break;
//case 2
//sub();
//break;
//case 3
//mult();
//break;
//case 4
//div();
//break;
//default:
//System.err.println("wrong input");
// 
        Scanner O1 = new Scanner(System.in);
        System.out.println("Enter first numbers ");
        int a = O1.nextInt();
        System.out.println("Enter Second numbers ");
        int b = O1.nextInt();
        System.out.println("Enter a number \n1 : addition \n2 : subtraction \n3 : multiplication\n 4: division");
        int ch = O1.nextInt();
        switch (ch) {
            case 1:
                System.out.println("Addition is : " + (a + b));
                break;
            case 2:
                System.out.println("Subtraction is : " + (a - b));
                break;
            case 3:
                System.out.println("Multiplication is : " + (a * b));
                break;
            case 4:
                System.out.println("Division is : " + (a / b));
                break;
            default:
                System.err.println("wrong input");
        }
    }

}


Comments

Popular posts from this blog

RunwayWithCode

web development Lectures

C++ Lectures