Class 8 Computer

Mid-Term Syllabus

Final-Term Syllabus

Class 8 Java Booklet Questions

Question 1
Write a Java program to display the following pattern:

J
JA
JAV
JAVA
JAV
JA
J
class Pattern{ 
    public static void main(String args[]){ 
        System.out.println(“J”); 
        System.out.println(“JA”); 
        System.out.println(“JAV”); 
        System.out.println(“JAVA”); 
        System.out.println(“JAV”); 
        System.out.println(“JA”); 
        System.out.println(“J”); 
    } 
}

Question 2
Write a Java program to display the following pattern:

@@@@@@@
@ @
@ @
@ @
@ @
@ @
@@@@@@@
class Pattern{ 
    public static void main(String args[]){ 
        System.out.println(“@@@@@@@”); 
        System.out.println(“@     @”); 
        System.out.println(“@     @”); 
        System.out.println(“@     @”); 
        System.out.println(“@     @”); 
        System.out.println(“@     @”); 
        System.out.println(“@@@@@@@”); 
    }
}

Question 3
Write a Java program to display the following pattern:

C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
class Compute{ 
    public static void main(String[] args){ 
        System.out.println("C"); 
        System.out.println("CO"); 
        System.out.println("COM"); 
        System.out.println("COMP"); 
        System.out.println("COMPU"); 
        System.out.println("COMPUT"); 
        System.out.println("COMPUTE"); 
    } 
}

Question 4
Write a Java program to display the following pattern using the escape sequences '\t' and '\n':

S       D       G       Goals
17 Goals
To Be Achieved
By 2030
class Goals{ 
    public static void main(String args[]){ 
        System.out.println(“S\tD\tG\tGoals”); 
        System.out.println(“17\tGoals\nTo\tBe\tAchieved”); 
        System.out.println(“By\t2030”); 
    } 
}

Question 5
Write a Java program to display your biodata that consists of your name, father’s name, date of birth, address, contact number and e-mail ID.

class BioData{ 
    public static void main(String args[]){ 
        System.out.println("BIO-DATA"); 
        System.out.println("Name: FirstName LastName"); 
        System.out.println("Father's Name : FirstName LastName");
        System.out.println("Date of Birth: 01-01-2012");
        System.out.println("Address: Asansol, West Bengal");  
        System.out.println("Contact Number: 9876543210"); 
        System.out.println("Email ID: username@mydomain.com"); 
    } 
}

Question 6
Write a Java program to assign two numbers 1273 and 58 in suitable variables and find and display their sum, difference, product, quotient and remainder with proper messages.

class Calculation{ 
    public static void main(String args[]){ 
        int a = 1273; 
        int b = 58; 
        int sum = a + b; 
        int diff = a - b; 
        int prod = a * b; 
        int quo = a / b; 
        int rem = a % b; 
        System.out.println("Sum = " + sum); 
        System.out.println("Difference = " + diff); 
        System.out.println("Product = " + prod); 
        System.out.println("Quotient = " + quo); 
        System.out.println("Remainder = " + rem); 
    } 
}

Question 7
Write a Java program to assign 5769 in a variable and find and display its double, half and two-fifth.

class Compute{ 
    public static void main(String args[]){ 
        int a = 5769; 
        int d = a * 2; 
        double h = a / 2.0; 
        double f = 2 / 5.0 * a; 
        System.out.println("Double = " + d); 
        System.out.println("Half = " + h); 
        System.out.println("2/5th = " + f); 
    } 
}

Question 8
A shopkeeper buys a TV set for ₹32,500 and sells it at a profit of 15%. On this selling price, a GST of 18.5% and a service charge of 1.25% are charged. Find and display the total selling price, profit, GST and service charge.

class Television{ 
    public static void main(String args[]){ 
        int cp = 32500; 
        float p = 15 / 100.0F * cp; 
        float sp = cp + p; 
        float gst = 18.5 / 100.0F * sp; 
        float sc = 1.25 / 100.0F * sp;
        float tsp = sp+ gst + sc;
        System.out.println("Total Selling Price = " + tsp);
        System.out.println("Profit = " + p);
        System.out.println("GST = " + gst);
        System.out.println("Service Charge = " + sc);
    } 
}

Question 9
A man purchased an old bicycle for ₹1,200 and spent ₹250 on repairs, ₹350 on paint and added new accessories worth ₹500. He wants to make a profit of ₹1,500 on selling the cycle. Find the selling price of the cycle. Write a Java program to store all the values and calculate and display the selling price and the profit % of the cycle.

class Cycle{
    public static void main(String args[]){ 
        int cp = 1200;
        int repair = 250;
        int paint = 350;
        int acc = 500;
        int profit = 1500;
        int tcp = cp + repair + paint + acc;
        int sp = tcp + profit;
        double pp = p * 100.0 / tcp;
        System.out.println("Selling Price = " + sp); 
        System.out.println("Profit % = " + pp); 
    } 
}

Question 10
A train covers 120.500 km in 2 hours, next 160.750 km in 1 hour and the last 240.250 km in 3 hours. Write a Java program to store all the values and find and display the average speed.

class Train{ 
    public static void main(String args[]){ 
        float d1 = 120.500F, d2 = 160.750F, d3 = 140.250F; 
        int t1 = 2, t2 = 1, t3 = 3; 
        float td = d1 + d2 + d3; 
        int tt = t1 + t2 + t3; 
        float speed = td / tt; 
        System.out.println("Average Speed = " + speed); 
    } 
}

Question 11
An alloy consists of 13 parts of copper, 7 parts of zinc and 5 parts of nickel. Write a Java program to store all the values and calculate and display the percentage of each metal in the alloy.

class Alloy{ 
    public static void main(String args[]){ 
        int c = 13, z = 7, n = 5; 
        int sum = c + z + n; 
        float pc = c * 100.0F / sum; 
        float pz = z * 100.0F / sum; 
        float pn = n * 100.0F / sum; 
        System.out.println("Percentage of Copper = " + pc); 
        System.out.println("Percentage of Zinc = " + pz); 
        System.out.println("Percentage of Nickel = " + pn); 
    } 
}

Question 12
A salesperson sells goods worth ₹4325, ₹4996.50, ₹8935 and ₹9960.75 in four consecutive months. Write a Java program to store the above values and calculate and display the total and average sales.

class Sales{ 
    public static void main(String args[]){ 
        double s1 = 4325;
        double s2 = 4996.50;
        double s3 = 8935;
        double s4 = 9960.75; 
        double total = s1 + s2 + s3 + s4; 
        double avg = total / 4; 
        System.out.println("Total Sales = " + total); 
        System.out.println("Average Sales = " + avg); 
    } 
}

Question 13
The average height of 8 boys is 157 cm. When the 9th boy joins the group, the average height changes to 159 cm. Write a Java program to store the above data and find and display the height of the 9th boy.

class Height{ 
    public static void main(String args[]){ 
        int avg8 = 157
        int avg9 = 159; 
        int tot8 = avg8 * 8; 
        int tot9 = avg9 * 9; 
        int h9 = tot9 - tot8; 
        System.out.println("Height of 9th boy = " + h9 + " cm"); 
    } 
}

Question 14
The angles of a quadrilateral are in the ratio 14:6:8:10. Write a Java program to store the given data and find and display the measure of each angle of the quadrilateral.

class Quadrilateral{ 
    public static void main(String args[]){ 
        int a = 14, b = 6, c = 8, d = 10; 
        int tot = a + b + c + d; 
        double a1 = a * 360.0 / tot; 
        double a2 = b * 360.0 / tot; 
        double a3 = c * 360.0 / tot; 
        double a4 = d * 360.0 / tot; 
        System.out.println("First Angle = " + a1); 
        System.out.println("Second Angle = " + a2); 
        System.out.println("Third Angle = " + a3); 
        System.out.println("Fourth Angle = " + a4); 
    } 
}

Question 15
Write a Java program to input two integers and find and display their sum, difference, product, quotient and remainder.

import java.io.*; 
class Solve{ 
    public static void main(String[] args)throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter first Number: "); 
        int a = Integer.parseInt(in.readLine()); 
        System.out.print("Enter second Number: "); 
        int b = Integer.parseInt(in.readLine ()); 
        int sum = a + b; 
        int diff = a - b; 
        int prod = a * b; 
        int quo = a / b; 
        int rem = a % b; 
        System.out.println("Sum = " + sum); 
        System.out.println("Difference = " + diff); 
        System.out.println("Product = " + prod); 
        System.out.println("Quotient = " + quo); 
        System.out.println("Remainder = " + rem); 
    } 
}

Question 16
Write a Java program to input the number of pencils and erasers purchased and compute and display the total bill when one pencil costs ₹5.25 and one eraser costs ₹4.75.

import java.io.*; 
class Purchase{ 
    public static void main(String[] args)throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        double cp = 5.25;
        double ce = 4.75;
        double bill = 0.0; 
        System.out.print("Number of pencils: "); 
        int np = Integer.parseInt(in.readLine()); 
        System.out.print("Number of erasers: "); 
        int ne = Integer.parseInt(in.readLine()); 
        bill = np * cp + ne * ce; 
        System.out.println("Total Bill = " + bill); 
    } 
}

Question 17
Write a Java program to enter the principal amount, rate of interest per annum and time in years. Calculate and display the simple interest and amount.

import java.io.*; 
class Interest{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter Principal: "); 
        double p = Double.parseDouble(in.readLine()); 
        System.out.print("Enter Rate: "); 
        double r = Double.parseDouble(in.readLine()); 
        System.out.print("Enter Time: "); 
        double t = Double.parseDouble(in.readLine()); 
        double si = p * t * r / 100.0; 
        double a = p + si; 
        System.out.println("Simple Interest = " + si); 
        System.out.println("Amount = " + a); 
    } 
}

Question 18
Write a Java program to enter the length and breadth of a rectangular field. Calculate and display its area, perimeter and diagonal.

import java.io.*; 
class Rectangle{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter length: "); 
        double l = Double.parseDouble(in.readLine()); 
        System.out.print("Enter breadth: "); 
        double b = Double.parseDouble(in.readLine()); 
        double a = l * b; 
        double p = 2 * (l + b); 
        double d = Math.sqrt(l * l + b * b); 
        System.out.println("Area = " + a); 
        System.out.println("Perimeter = " + p); 
        System.out.println("Diagonal = " + d); 
    } 
}

Question 19
Write a Java program to input a student’s roll (int), name (String), class (String), section (char), marks scored in three subjects (float). Calculate and display the total and average marks.

import java.io.*; 
class Student{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        int roll; 
        float tot = 0.0F, m1, m2, m3, avg = 0.0F; 
        char sec; 
        String name, std; 
        System.out.print("Roll number: "); 
        roll = Integer.parseInt(in.readLine()); 
        System.out.print("Name: "); 
        name = in.readLine(); 
        System.out.print("Class: "); 
        std = in.readLine(); 
        System.out.print("Section: "); 
        sec = in.readLine().charAt(0); 
        System.out.print("Marks in Subject 1: "); 
        m1 = Float.parseFloat(in.readLine()); 
        System.out.print("Marks in Subject 2: "); 
        m2 = Float.parseFloat(in.readLine()); 
        System.out.print("Marks in Subject 3: "); 
        m3 = Float.parseFloat(in.readLine()); 
        tot = m1 + m2 + m3; 
        avg = tot / 3.0F; 
        System.out.println("Total marks: " + tot); 
        System.out.println("Average marks: " + avg); 
    } 
}

Question 20
Write a Java program to input the number of days from the user and display it in years, months and days.
Example:
INPUT: 500 days
OUTPUT: 1 year(s) 4 month(s) 15 day(s)

import java.io.*; 
class Convert{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Number of days:"); 
        int d = Integer.parseInt(in.readLine()); 
        int y = d / 365; 
        d = d % 365; 
        int m = d / 30; 
        d = d % 30; 
        System.out.println(y + “ year(s) “ + m + “ month(s) “ + d + “ day(s)”); 
    } 
}

Question 21
Write a Java program to input the basic pay for an employee. Calculate DA, HRA, PF, Gross Pay and Net Pay. Display the Gross Pay and the Net Pay, where DA = 50% of basic pay, HRA = 20% of basic pay, PF = 12.25% of basic pay.
Gross Pay = Basic Pay + DA + HRA
Net Pay = Gross Pay – PF

import java .io.*; 
class Salary{ 
    public static void main(String[] args)throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter basic pay: "); 
        double bp = Double.parseDouble(in.readLine()); 
        double da = 50 / 100.0 * bp; 
        double hra = 20 /100.0 * bp; 
        double pf = 12.25 / 100.0 * bp; 
        double gp = bp + da + hra; 
        double np = gp - pf; 
        System.out.println("Gross Pay = " + gp); 
        System.out.println("Net Pay = " + np); 
    } 
}

Question 22
Write a Java program to enter the temperature in Fahrenheit and convert and display it in Celsius using the formula: C = 5 × (F – 32) / 9

import java .io.*; 
class Convert{ 
    public static void main(String[] args)throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Temperature in Fahrenheit: "); 
        double f = Double.parseDouble(in.readLine()); 
        double c = 5.0 / 9 * (f - 32); 
        System.out.println("Temperature in Celsius: " + c); 
    } 
}

Question 23
Write a Java program to enter the measure of three sides of a triangle and calculate and display its area using the formula:
Area of Triangle Formula

import java .io.*; 
class Triangle{ 
    public static void main(String[] args)throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.println("Enter the three side of the triangle: "); 
        double a = Double.parseDouble(in.readLine()); 
        double b = Double.parseDouble(in.readLine()); 
        double c = Double.parseDouble(in.readLine()); 
        double s = (a + b + c) / 2.0; 
        double area = Math.sqrt(s * (s - a) * (s - b) * (s - c)); 
        System.out.println("Area of the triangle = " + area); 
    } 
}

Question 24
Write a Java program to input the radius and the height of a cone. Calculate and print the volume of the cone using the formula:
Cone Volume

import java.io.*; 
class Cone{ 
    public static void main(String[] args)throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.println("Enter the radius: "); 
        double r = Double.parseDouble(in.readLine()); 
        System.out.println("Enter the height: "); 
        double h = Double.parseDouble(in.readLine()); 
        double v = 1.0 / 3 * 3.14 * Math.pow(r, 2) * h; 
        System.out.println("Area of Cone = " + v); 
    } 
}

Question 25
Write a Java program to input any two integers from the user. Now swap/interchange their values and then display those variables.

import java.io.*; 
class Swap{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter first integer: "); 
        int a = Integer.parseInt(in.readLine()); 
        System.out.print("Enter second integer: "); 
        int b = Integer.parseInt(in.readLine()); 
        int temp = a; 
        a = b; 
        b = temp; 
        System.out.println("a = " + a); 
        System.out.println("b = " + b); 
    } 
}

Question 26
Write a Java program to enter distance in km and time in hours. Calculate and display the speed in km/h and m/s.

import java .io.*; 
class Speed{ 
    public static void main(String[] args)throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Distance in kilometer: "); 
        double d = Double.parseDouble(in.readLine()); 
        System.out.print("Time in hours: "); 
        double t = Double.parseDouble(in.readLine()); 
        double s1 = d / t; 
        double s2 = s1 * 5.0 / 18; 
        System.out.println("Speed in km/h = " + s1); 
        System.out.println("Speed in m/s = " + s2); 
    } 
}

Question 27
Write a Java program to input values of variables u, a, and t. Find and display the value of the following expression:
s = ut + 1/2 at^2

import java.io.*; 
class Expression{ 
    public static void main(String[] args)throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("a = "); 
        double a = Double.parseDouble(in.readLine()); 
        System.out.print("t = "); 
        double t = Double.parseDouble(in.readLine()); 
        System.out.print("u = "); 
        double u = Double.parseDouble(in.readLine()); 
        double s = u * t + 1.0 / 2 * a * Math.pow(t, 2); 
        System.out.println("s = " + s); 
    } 
}

Question 28
Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women. The formula to calculate BMI is:
BMI Formula

import java.io.*; 
class BMI{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Weight in kg: "); 
        double w = Double.parseDouble(in.readLine()); 
        System.out.print("Height in meters: "); 
        double h = Double.parseDouble(in.readLine()); 
        double b = w / Math.pow(h, 2); 
        System.out.println("BMI value = " + b); 
    } 
}

Question 29
A shopkeeper offers 5% discount on the total bill. Write a Java program to input the customer’s total bill and calculate and display the final amount to be paid by the customer after giving discount.

import java.io.*; 
class Shop{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter the total bill: "); 
        double bill = Double.parseDouble(in.readLine()); 
        double discount = 5.0 / 100 * bill; 
        double amount = bill - discount; 
        System.out.println("Amount to be paid = " + amount); 
    } 
}

Question 30
Write a Java program to input the measure of the side of a square and calculate and display the measure of its diagonal using the formula:
Square Diagonal

import java.io.*; 
class Square{ 
    public static void main(String args[])throws IOException{ 
        System.out.print("Measure of the side: "); 
        double s = Double.parseDouble(in.readLine()); 
        double d = Math.sqrt(2) * s; 
        System.out.println("Measure of the diagonal = " + d); 
    } 
}

Question 31
Write a Java program to input an integer. Test and print if the number is positive, negative or zero.

import java.io.*; 
class Check{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter Any Number: "); 
        int n = Integer.parseInt(in.readLine()); 
        if(n > 0) 
            System.out.println(n + " is positive."); 
        if(n < 0) 
            System.out.println(n + " is negative."); 
        if(n == 0) 
            System.out.println("It is zero."); 
    } 
}

Question 32
Write a Java program to input the cost price and the selling price of an article. Find and display the profit and the profit percent, or loss and loss percent, or if the CP is equal to SP then display “No Profit, No Loss”.

import java.io.*; 
class ProfitLoss{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in);
        System.out.print("Enter cost price: "); 
        double cp = Double.parseDouble(in.readLine()); 
        System.out.print("Enter selling price: "); 
        double sp = Double.parseDouble(in.readLine()); 
        if(sp > cp){ 
            double p = sp - cp; 
            double pp = p * 100.0 / cp; 
            System.out.println("Profit = " + p); 
            System.out.println("Profit % = " + pp); 
        } 
        if(cp > sp){ 
            double l = cp - sp; 
            double lp = l * 100.0 / cp; 
            System.out.println("Loss = " + l); 
            System.out.println("Loss % = " + lp); 
        } 
        if(cp == sp) 
            System.out.println("No Profit, No Loss"); 
    } 
}

Question 33
Write a Java program to input an integer. Test and print if the number is even or odd.

import java.io.*; 
class Check{ 
    public static void main(String args[]) throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter the number: "); 
        int n = Integer.parseInt(in.readLine()); 
        if(n % 2 == 0) 
            System.out.println(n + " is even."); 
        else 
            System.out.println(n + " is odd."); 
    } 
}

Question 34
Write a Java program to input an integer. If the number is negative, then display its square, otherwise display its square root.

import java.io.*; 
class Check{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter the integer: "); 
        int num = Integer.parseInt(in.readLine()); 
        if(num < 0){ 
            int s = num * num; 
            System.out.println("Square = " + s); 
        } 
        else{ 
            double root = Math.sqrt(num); 
            System.out.println("Square root = " + root); 
        } 
    } 
}

Question 35
Write a Java program to input an integer. Test and print whether it is a perfect square or not. A perfect square is a number that can be expressed as the square of an integer. Example: 25.

import java.io.*; 
class PerfectSquare{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter the number: "); 
        int n = Integer.parseInt(in.readLine()); 
        double root = Math.sqrt(n); 
        if(root == (int)root) 
            System.out.println(n + " is a perfect square."); 
        else 
            System.out.println(n + " is not a perfect square."); 
    } 
}

Question 36
Write a Java program to input the measure of two angles. Find and display whether they are complementary angles or not. Two angles are complementary if their sum equals 90 degrees.

import java.io.*; 
class Complementary{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("First angle: "); 
        int a = Integer.parseInt(in.readLine()); 
        System.out.print("Second angle: "); 
        int b = Integer.parseInt(in.readLine()); 
        int s = a + b; 
        if(s == 90) 
            System.out.println("They are complementary angles."); 
        else 
            System.out.println("They are not complementary angles."); 
    } 
}

Question 37
A shopkeeper offers discounts on the net bill. Write a Java program to input the net bill and calculate and display the discount amount and the final amount to be paid, based on the following table:

Net Bill in RupeesDiscount%
Below 50005%
5000 to below 1000010%
10000 and above15%
import java.io.*; 
class Shopkeeper{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter net bill: "); 
        int nb = Integer.parseInt(in.readLine()); 
        double dp = 0.0; 
        if(nb < 5000) 
            dp = 5.0; 
        if(nb >= 5000 && nb < 10000) 
            dp = 10.0; 
        if(nb >= 10000) 
            dp = 15.0; 
        double da = dp / 100.0 * nb; 
        double amt = nb - dis; 
        System.out.println("Discount % = " + dp); 
        System.out.println("Discount Amount = " + dis); 
        System.out.println("Amount Payable after Discount = " + amt); 
    } 
}

Question 38
Write a Java program that will allow a teacher to input the marks obtained in Physics, Chemistry and Biology, and find and display the average marks and grade based on the following table:

Average MarksGrade
Up to 50D
Above 50 and up to 70C
Above 70 and up to 90B
Above 90A
import java.io.*; 
class Grade{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        char gr = '\u0000'; 
        System.out.print("Marks in Physics: "); 
        int phy = Integer.parseInt(in.readLine()); 
        System.out.print("Marks in Chemistry: "); 
        int chem = Integer.parseInt(in.readLine()); 
        System.out.print("Marks in Biology: "); 
        bio = Integer.parseInt(in.readLine()); 
        double avg = (phy + chem + bio) / 3.0; 
        if(avg <= 50) 
            gr = 'D'; 
        if(avg > 50 && avg <= 70) 
            gr = 'C'; 
        if(avg > 70 && avg <= 90) 
            gr = 'B'; 
        if(avg > 90 && avg <= 100) 
            gr = 'A'; 
        System.out.println("Average marks: " + avg); 
        System.out.println("Grade: " + gr); 
    } 
}

Question 39
A salesman is paid commission based on the following table:

Sales Amount in RupeesCommission%
Up to 100002%
Above 10000 and up to 200004%
Above 20000 and up to 500008%
Above 5000015%

Write a Java program to input the sales amount and calculate and display the commission % and the commission amount.

import java.io.*; 
class Commission{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter sales amount: "); 
        double s = Integer.parseInt(in.readLine()); 
        double cp = 0.0; 
        if(s <= 10000) 
            cp = 2.0; 
        if(s > 10000 && s <= 20000) 
            cp = 4.0; 
        if(s > 20000 && s <= 50000) 
            cp = 8.0; 
        if(s > 50000) 
            cp = 15.0; 
        double amt = cp / 100.0 * sa; 
        System.out.println("Commission % = " + cp); 
        System.out.println("Commission Amount = " + amt); 
    } 
}

Question 40
Write a Java program to enter basic pay and compute Dearness Allowance (DA) and House Rent Allowance (HRA) based on the following table:

Basic Pay in RupeesDA%HRA%
Up to 3000050%20%
Above 30000 and up to 5000065.5%22.75%
Above 5000070%30%

Calculate DA, HRA and Gross Pay.
Gross Pay = Basic Pay + DA + HRA

import java.io.*; 
class Salary{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter basic pay : "); 
        double bp = Double.parseDouble(in.readLine()); 
        double da = 0.0, hra = 0.0, gp = 0.0; 
        if(bp <= 30000){ 
            dp = 50.0; 
            hra = 20.0; 
        } 
        if(bp > 30000 && bp <= 50000){ 
            dp = 65.5; 
            hra = 22.75; 
        } 
        if(bp > 50000){ 
            dp = 70.0; 
            hra = 30.0; 
        } 
        da = da / 100.0 * bp; 
        hra = hra / 100.0 * bp; 
        gp = bp + da + hra; 
        System.out.println("Gross Pay = " + gp); 
    } 
}

Question 41
Write a Java program to allow the user to input any character from the keyboard and check and display whether it is an uppercase alphabet, or a lowercase alphabet, or a digit.

import java.io.*; 
class Check{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter the character: "); 
        char ch = in.readLine().charAt(0); 
        if(ch >= 'A' && ch <= 'Z') 
            System.out.println("It is an uppercase alphabet"); 
        if(ch >= 'a' && ch <= 'z') 
            System.out.println("It is a lowercase alphabet"); 
        if(ch >= '0' && ch <= '9') 
            System.out.println("It is a digit"); 
    } 
}

Question 42
Write a Java program to input any three different integers and find and display the greatest among these integers.

import java.io.*; 
class Greatest{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.println("Enter three integers:"); 
        int a = Integer.parseInt(in.readLine()); 
        int b = Integer.parseInt(in.readLine()); 
        int c = Integer.parseInt(in.readLine()); 
        int max = 0; 
        if(a > b && a > c) 
            max = a; 
        if(b > a && b > c) 
            max = b; 
        if(c > a && c > b) 
            max = c; 
        System.out.println("Maximum Number is " + max); 
    } 
}

Question 43
Write a Java program to enter the number of units consumed for electricity bill. Find and display the total electricity bill based on the following table:

Units consumedRate per unit
First 200 units₹4.50
Next 200 units₹5.50
Above 400 units₹6.50

Apart from this every consumer pays a meter rent of ₹35.

import java.io.*; 
class Electricity{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        double bill = 0.0; 
        System.out.print("Number of units consumed: "); 
        int u = Integer.parseInt(in.readLine()); 
        if(u <= 200) 
            bill = u * 4.5; 
        if(u > 200 && u <= 400) 
            bill = 200 * 4.5 + (u - 200) * 5.5; 
        if(u > 400) 
            bill = 200 * 4.5 + 200 * 5.5 + (u - 400) * 6.5; 
        bill = bill + 35; 
        System.out.println("Bill with Meter Rent = " + bill); 
    } 
}

Question 44
Write a Java program to input an integer and check whether it is a Buzz number or not. A Buzz number is an integer that is either divisible by 7 or contains 7 in the unit’s place. Examples: 28, 47, etc.

import java.io.*; 
class Buzz{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter the integer: "); 
        int n = Integer.parseInt(in.readLine()); 
        if(n % 7 == 0 || n % 10 == 7) 
            System.out.println(n + " is a buzz number."); 
        else 
            System.out.println(n + " is not a buzz number."); 
    } 
}

Question 45
Write a Java program to input the measure of an angle and check whether it is an acute angle or a right angle or a straight angle or an obtuse angle.

import java .io.*; 
class Angle{ 
    public static void main(String args[]){ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter the angle: "); 
        int a=Integer.parseInt(in.readLine()); 
        if(a > 0 && a < 90) 
            System.out.println("It is an acute angle"); 
        if(a == 90) 
            System.out.println("It is a right angle"); 
        if(a > 90 && a < 180) 
            System.out.println("It is an obtuse angle"); 
        if(a == 180) 
            System.out.println("It is a straight angle"); 
    } 
} 

Question 46
Write a Java program to print the following series: -100, -90, -80, … 80, 90, 100.

class Series{ 
    public static void main(String args[]){ 
        for(int i = -100; i <= 100; i += 10) 
            System.out.print(i + "\t"); 
    } 
}

Question 47
Write a Java program to print the following series: 10, 20, 30, 40, … N terms.

import java.io.*; 
class Series{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter number of terms: "); 
        int n = Integer.parseInt(in.readLine()); 
        for(int i = 1; i <= n; i++) 
            System.out.print((i * 10) + " "); 
    } 
}

Question 48
Write a Java program to input an integer and print its multiplication table (up to 20 multiples) in the following format:
7 × 1 = 7
7 × 2 = 14

7 × 20 = 140

import java.io.*; 
class Table{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        System.out.print("Enter the number: "); 
        int n = Integer.parseInt(in.readLine()); 
        for(int i = 1; i <= 20; i++) 
        System.out.println(n + " x " + i + " = " + (n * i)); 
    } 
}

Question 49
Write a Java program to input 20 integers and count and display how many of these are positive, negative and zero.

import java.io.*; 
class Counting{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        int pos = 0;
        int neg = 0;
        int zero = 0; 
        for(int i = 1; i <= 20; i++){ 
            System.out.print("Enter the integer: "); 
            int n = Integer.parseInt(in.readLine()); 
            if(n > 0) 
                pos++; 
            if(n < 0) 
                neg++; 
            if(n == 0) 
                zero++; 
        } 
        System.out.println("Number of positive numbers = " + pos); 
        System.out.println("Number of negative numbers = " + neg); 
        System.out.println("Number of zeroes = " + zero); 
    } 
}

Question 50
Write a Java program to input any 10 integers from the user and find and display the greatest and the smallest integers among those integers.

import java.io.*; 
class Find{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter the integer: "); 
        int n = Integer.parseInt(in.readLine()); 
        int max = n;
        int min = n; 
        for(int i = 1; i <= 9; i++){ 
            System.out.print("Enter the integer: "); 
            n = Integer.parseInt(in.readLine()); 
            if(n > max) 
                max = n; 
            if(n < min) 
                min = n;
        }
        System.out.println("Greatest integer = " + max); 
        System.out.println("Smallest integer = " + min); 
    } 
}

Question 51
Write a Java program to input n integers. Find and display the sum of even and odd numbers separately.

import java.io.*; 
class Solve{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        int even = 0;
        int odd = 0; 
        System.out.print("How many numbers to input? "); 
        int n = Integer.parseInt(in.readLine()); 
        for(int i = 1; i <= n; i++){ 
         System.out.print("Enter the integer: "); 
         int x = Integer.parseInt(in.readLine()); 
         if(x % 2 == 0) 
             even += x; 
         else 
             odd += x; 
        } 
        System.out.println("Sum of even numbers = " + even); 
        System.out.println("Sum of odd numbers = " + odd); 
    } 
}

Question 52
Write a Java program to generate and print the first N terms of the Fibonacci series. The first few terms of the series are: 0, 1, 1, 2, 3, 5, 8, 13, … N terms. This series starts from 0 and 1 and the next term is the sum of the previous two.

import java.io.*; 
class Fibonacci{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        int a = 0; 
        int b = 1; 
        System.out.print("Number of terms: "); 
        int n = Integer.parseInt(in.readLine()); 
        System.out.print(a + " " + b + " "); 
        for(int i = 3; i <= n; i++){ 
            c = a + b; 
            System.out.print(c + " "); 
            a = b; 
            b = c; 
        } 
    } 
}

Question 53
A company wishes to generate salary slips for 5 employees. Write a Java program to enter the basic pay and compute the Dearness Allowance (DA) and House Rent Allowance (HRA) based on the following table:

Basic Pay in RupeesDA%HRA%
Up to 3000058.512.0
Above 30000 and up to 500006516.5
Above 500007324.8

Calculate DA, HRA and Gross Pay.
Gross Pay = Basic Pay + DA + HRA
Display the gross pay of each employee.

import java.io.*; 
class Employee{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        double da = 0.0;
        double hra = 0.0; 
        for(int i = 1;i <= 5; i++){ 
            System.out.print("Enter Basic Pay: "); 
            double b = Double.parseDouble(in.readLine()); 
            if(bp <= 30000){ 
                da = 58.5; 
                hra = 12.0; 
            } 
            if(bp > 30000 && bp <= 50000){ 
                da = 65.0; 
                hra = 16.5; 
            } 
            if(bp >= 50000){ 
                da = 73.0; 
                hra = 24.8; 
            } 
            da = da / 100.0 * bp; 
            hra = hra / 100.0 * bp; 
            double gp = bp + da + hra; 
            System.out.println("Gross Pay = " + gp); 
        } 
    } 
}

Question 54
Write a Java program to display the sum of the following series:
Question 54 Series

import java.io.*; 
class Series{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        double s = 0.0; 
        System.out.print("Enter the value of N: "); 
        int n = Integer.parseInt(in.readLine()); 
        System.out.print("Enter value of a: "); 
        int a = Integer.parseInt(in.readLine()); 
        for(int i = 1; i <= n; i++) 
            s += i / Math.pow(a, i); 
        System.out.println("Sum of Series = " + s); 
    } 
}

Question 55
Write a Java program to display the sum of the following series:
Question 55 Series

import java.io.*; 
class Series{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        double s = 0.0; 
        int x = 1; 
        System.out.print("Enter value of n: "); 
        int n = Integer.parseInt(in.readLine()); 
        System.out.print("Enter value of a: "); 
        int a = Integer.parseInt(in.readLine()); 
        for(int i = 1; i <= n; i++){ 
            s = s + (x / Math.pow(a, (x + 1))); 
            x = x + 2; 
        } 
        System.out.println("Sum of series = " + s); 
    } 
}

Question 56
Write a Java program to input 10 integers. Count and display how many of these numbers are multiples of 5. Also display the sum and the average of those 10 integers.

import java.io.*; 
class Solve{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in= new DataInputStream(System.in); 
        int sum = 0;
        int f = 0; 
        for(int i = 1; i <= 10; i++){ 
            System.out.print("Enter the integer: "); 
            int n = Integer.parseInt(in.readLine()); 
            sum = sum + n; 
            if(n % 5 == 0) 
                f++; 
        } 
        double avg = sum / 10.0; 
        System.out.println("Sum of the integers = " + sum); 
        System.out.println("Average of the integers = " + avg); 
        System.out.println("Frequency of numbers divisible by 5 = " + f); 
    } 
}

Question 57
Write a program to input an integer and find and print its factorial. The factorial of a
number is the product of all the numbers from 1 to that number. Example: Factorial of 5 = 1 × 2 × 3 × 4 × 5 = 120

import java .io.*; 
class Factorial{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        long f = 1L; 
        System.out.print("Enter the number: "); 
        int n = Integer.parseInt(in.readLine()); 
        for(int i = 1; i <= n; i++) 
            f *= i; 
        System.out.println("Factorial = " + f); 
    } 
}

Question 58
Write a Java program to input any integer. Now check whether it is a prime number or not. A prime number is a number which has only two factors (1 and itself). Examples are 2, 3, 5, 7, 11, 13, etc.

import java .io.*; 
class Prime{ 
    public static void main(String args[]){ 
        DataInputStream in= new DataInputStream(System.in); 
        int f = 0; 
        System.out.print("Enter any number : "); 
        int n = Integer.parseInt(in.readLine()); 
        for(int i = 1; i <= n; i++){ 
            if(n % i == 0) 
                f++; 
        } 
        if(f == 2) 
            System.out.println("It is a prime number!"); 
        else 
            System.out.println("It is not a prime number."); 
    } 
}

Question 59
Write a Java program to input any integer and print all the factors of that number.
Example: Factors of 15 are 1, 3, 5, 15.

import java.io.*; 
class Factors{ 
    public static void main(String args[]){ 
        DataInputStream in = new DataInputStream(System.in); 
        System.out.print("Enter any number: "); 
        int n = Integer.parseInt(in.readLine()); 
        System.out.println("Factors are:"); 
        for(int i = 1; i <= n; i++){ 
            if(n % i == 0) 
                System.out.println(i); 
        } 
    } 
}

Question 60
Write a Java program to input an integer. Find and display whether it is a perfect number or
not. A perfect number is one whose sum of its proper factors (factors excluding the number itself) is same as the original number.
Example: 6 is a perfect number. Factors of 6 (excluding 6) are 1, 2, 3.
1 + 2 + 3 = 6 (same as the original number)
Thus, 6 is a perfect number.

import java.io.*; 
class PerfectNumber{ 
    public static void main(String args[])throws IOException{ 
        DataInputStream in = new DataInputStream(System.in); 
        int s = 0; 
        System.out.print("Enter the integer: "); 
        int n = Integer.parseInt(in.readLine()); 
        for(int i = 1; i <= n / 2; i++){ 
        if(n % i == 0) 
            s += i; 
        } 
        if(n == s) 
            System.out.println("It is a perfect number"); 
        else 
            System.out.println("It is not a perfect number"); 
    } 
}