Java Programming (Conditionals and Switch Statement)

Vinnu Mukhi
2 min readMay 14, 2021

Q. Write a program to find out whether a student is pass or fail?

package com.company;
import java.util.Scanner;

public class exception {
public static void main(String[] args) {
byte m1,m2,m3;
Scanner sc= new Scanner(System.in);
System.out.println("Enter Your Marks in Physics");
m1= sc.nextByte();
System.out.println("Enter Your Marks in chemistry");
m2= sc.nextByte();
System.out.println("Enter your Marks in maths");
m3= sc.nextByte();

float avg= (m1+m2+m3)/3.0f;
System.out.println("Overall percentage is " + avg);
if (avg>=40 && m1>=33 && m2>=33 && m3>=33){
System.out.println("Congo You are Passed and You have been promoted!");
}
else {
System.out.println("Sorry! You are fail and You have not been promoted");
}
}
}
Output: Enter Your Marks in Physics
45
Enter Your Marks in chemistry
45
Enter your Marks in maths
45
Overall percentage is 45.0
Congo You are Passed and You have been promoted!

Q. Calculate Income Tax paid by an employee to the Government

public class exception {
public static void main(String[] args) {Scanner sc= new Scanner(System.in);
System.out.println("Enter Your Income in Lakhs per annum");
float tax = 0;
float income = sc.nextFloat();
if (income < 2.5){
tax = tax + 0;
}
else if (income>2.5f && income<=5f){
tax= tax +0.05f * (income - 2.5f);
}
else if (income>5f && income<=10f){
tax= tax +0.05f * (5.0f - 2.5f);
tax= tax +0.2f * (income - 5f);
}
else if (income>10.0f){
tax= tax +0.05f * (5.0f - 2.5f);
tax= tax +0.2f * (10.0f - 5f);
tax= tax +0.3f * (income - 10.0f);
}
System.out.println("The total tax paid by the employee is: " + tax);
}
}
Output: Enter Your Income in Lakhs per annum
18
The total tax paid by the employee is: 3.525

Q. Java program to find out the day of the week given the number.

import java.util.Scanner;

public class exception {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter number between 1 to 7");
int day= sc.nextInt();
switch (day) {

case 1 -> System.out.println("Monday");
case 2 -> System.out.println("Tuesday");
case 3 -> System.out.println("Wednesday");
case 4 -> System.out.println("Thrusday");
case 5 -> System.out.println("Friday");
case 6 -> System.out.println("Saturday");
case 7 -> System.out.println("Sunday");
}
}
}
Output: Enter a number between 1 to 7
4
Thrusday

--

--

Vinnu Mukhi
0 Followers

I'm a Computer Science Student from Indore (India) and I'm Sharing all my learnings here.