java practice question 5

/*
1.WHAT WILL BE OUTPUT OF THIS PROGRAM:
        int a = 10;
        if (a=11)
            System.out.println(“I am 11”);
        else
            System.out.println(“I am not 11”);


2.   Write a program to find out whether a student is pass or fail;
if it requires total 40% and at least 33% in each subject to pass.
Assume 3 subjects and take marks as an input from the user.

3. Calculate income tax paid by an employee to the government as per the slabs mentioned below:
         Income Slab    Tax
          2.5L – 5.0L  5%
          5.0L – 10.0L 20%
          Above 10.0L 30%
Note that there is not tax below 2.5L. Take the input amount as input from the user.

4. Write a Java program to find out the day of the week given the number
   [1 for Monday, 2 for Tuesday … and so on!]

5. Write a Java program to find whether a year entered by the user is a leap year or not.

6. Write a program to find out the type of website from the URL:
      .com – commercial website
      .org – organization website
      .in – Indian website


 */











package com.company;
import org.w3c.dom.ls.LSOutput;

import java.util.Scanner;

public class cwh_chapter4_practice_set {
    public static void main(String[] args) {

        //question1
        /*int a = 10;
        if (a=11)
            System.out.println(“I am 11”);
        else
            System.out.println(“I am not 11”);
        */
        //NOT RUN DUE TO ==


        //QUESTION2
        //as a a input from user then use import java.util.Scanner
        byte m1, m2, m3;
        Scanner sc = new Scanner(System.in);
        System.out.println("enter marks in physics");
        m1 = sc.nextByte();
        System.out.println("enter marks in chemistry");
        m2 = sc.nextByte();
        System.out.println("enter marks in mathematics");
        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("congratulation,promoted");
        } else {
            System.out.println("sorry,not promoted,try again");
        }


        //question3
        //Scanner sc = new Scanner(System.in);
        System.out.println("\t\nenter income lakh 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 <= 10.0f) {
            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 employ is:" + tax);


        //question4
        //Scanner sc = new Scanner(System.in);
        System.out.println("\t\nEnter the number: ");
        int day = sc.nextInt();
        switch (day) {//inhance switch case
            case 1 -> System.out.println("MONDAY");
            case 2 -> System.out.println("TUESDAY");
            case 3 -> System.out.println("WEDDAY");
            case 4 -> System.out.println("THRUSDAY");
            case 5 -> System.out.println("FRYDAY");
            case 6 -> System.out.println("SATURDAY");
            case 7 -> System.out.println("SUNDAY");
        }


        //question5
        //Scanner sc = new Scanner(System.in);
        System.out.println("\t\nEnter the year: ");
        int year = sc.nextInt();
        // Checking for a leap year.
        if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { // Conditions for a leap year.
            System.out.println("It's a leap year!"); // It is a leap year.
        } else {
            System.out.println("It is not a leap year"); // It is not a leap year.
        }


        //question6
        //Scanner sc = new Scanner(System.in);
        System.out.println("\t\nEnter the name of website: ");
        String website =sc.next();
        if(website.endsWith(".org")){
            System.out.println("this is a organization website");
        }
        else if(website.endsWith(".com")){
            System.out.println("this is a commertial website");
        }
        else if(website.endsWith(".in")){
            System.out.println("this is a indian website");
        }



    }

}

Comments

Popular posts from this blog

java chapter11 practice question on abstruct class and interfaces

java practice set 8

new stored procidure with interval and frequery code