If-else AND switch statement in Java

  program with  if-else statement in Java

package com.company;
import java.util.Scanner;
public class ifelse {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);

System.out.println("enter your marks in physics, math and english");
int a = s.nextInt();
int b= s.nextInt();
int c = s.nextInt();
float avg =(a+b+c)/3f;

if (avg>40 && a>33 && b>33 && c>33)
{
System.out.println("you are pass");
}
else
{
System.out.println("you are fail");
}
}
}

program with if  else-if  to find tax paid statement using Java

package com.company;
import java.util.Scanner;
public class taxpaid {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("enter your salary");
double a= s.nextInt();
if (a>=250000 && a<=500000)
{
double avg =(a*5)/100;
System.out.printf ("tax paid 1 %f",avg);
}
else if (a>500000 && a<100000)
{
double avg =(a*20)/100;
System.out.printf("\n tax paid 2 %f", avg);
}
else if (a>=100000)
{
double avg= (a*30)/100;
System.out.printf(" tax paid 3 %f",avg);
}
else {
System.out.println("no tax");
}

}

Program to find if you can drive or not (If-else) in java

package com.company;
import java.util.Scanner;
public class conditional {
public static void main(String[] args) {
System.out.println("enter your age");
Scanner s= new Scanner(System. in);
int a = s.nextInt();
if(a>=18)
{
System.out.println("you can drive");

}
else{
System.out.println("no, you can't drive");
}
}
}                                  

program with switch statement 

import java.util.Scanner;

public class enterdays {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int a = s.nextInt();
switch (a) {
case 1 -> System.out.println("Monday");
case 2 -> System.out.println("Tuesday");
case 3 -> System.out.println("wednesday");
case 4 -> System.out.println("thursday;");
case 5 -> System.out.println("friday");
case 6 -> System.out.println("saturday");
case 7 -> System.out.println("sunday");
}
}
}


No comments:

Post a Comment

    Hello, I'm Vishal Rana  I'm 19 years old  I live in Himachal Pradesh and  currently I'm studying in college for my UG degree...