Program is created using Switch-case and if else both. Switch case can be easily removed from this program.
import java.util.*;
public class Switchcase
{
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
System.out.println("please enter value of a");
int a = sc.nextInt();
System.out.println("please enter value of b");
int b = sc.nextInt();
System.out.println("please enter value of c");
int c = sc.nextInt();
System.out.println("please enter value of d");
int d = sc.nextInt();
int e=1;
switch(1)
{
case 1:
if (a>b&&a>c&&a>d)
{
System.out.println("Number a is greater than all");
}
else
{
if(b>a&&b>c&&b>d)
{
System.out.println("Number b is greater than all");
}
else
{
if(c>a&&c>b&&c>d)
{
System.out.println("Number c is greater than all");
}
else
{
if(d>a&&d>b&&d>c)
{
System.out.println("Number d is greater than all");
}
else
{
System.out.println("All numbers are equal");
}
}
}
}
}
}
}
import java.util.*;
public class Switchcase
{
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
System.out.println("please enter value of a");
int a = sc.nextInt();
System.out.println("please enter value of b");
int b = sc.nextInt();
System.out.println("please enter value of c");
int c = sc.nextInt();
System.out.println("please enter value of d");
int d = sc.nextInt();
int e=1;
switch(1)
{
case 1:
if (a>b&&a>c&&a>d)
{
System.out.println("Number a is greater than all");
}
else
{
if(b>a&&b>c&&b>d)
{
System.out.println("Number b is greater than all");
}
else
{
if(c>a&&c>b&&c>d)
{
System.out.println("Number c is greater than all");
}
else
{
if(d>a&&d>b&&d>c)
{
System.out.println("Number d is greater than all");
}
else
{
System.out.println("All numbers are equal");
}
}
}
}
}
}
}
No comments:
Post a Comment