Class IX ICSE - Input in Java - Program List
Class IX ICSE - Input in Java - Program List
import java.util.Scanner;
public class SimplePendulum {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
sc.close();
}
}
import java.util.Scanner;
public class EmployeePay {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
// Input
System.out.print("Enter Basic Pay of the employee: ");
double basicPay = sc.nextDouble();
// Calculations
double da = 0.30 * basicPay;
double hra = 0.15 * basicPay;
double pf = 0.125 * basicPay;
double grossPay = basicPay + da + hra;
double netPay = grossPay - pf;
// Output
System.out.println("Dearness Allowance (DA): " + da);
System.out.println("House Rent Allowance (HRA): " + hra);
System.out.println("Provident Fund (PF): " + pf);
System.out.println("Gross Pay: " + grossPay);
System.out.println("Net Pay: " + netPay);
sc.close();
}
}
import java.util.Scanner;
public class CameraPurchase {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
// Output
System.out.println("Discount: " + discount);
System.out.println("Price after discount: " + priceAfterDiscount);
System.out.println("GST (6%): " + gst);
System.out.println("Final amount to be paid: " + finalAmount);
sc.close();
}
}
4. A shopkeeper offers 30% discount on purchasing articles whereas the other
shopkeeper offers two successive discounts 20% and 10% for purchasing the same
articles. Write a program in Java to compute and display the discounts.
Take the price of an article as the input.
import java.util.Scanner;
public class DiscountComparison {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
// Output
System.out.println("\n--- Shopkeeper A ---");
System.out.println("Single 30% Discount: " + discountA);
System.out.println("Final Price: " + finalPriceA);
// Comparison
System.out.println("\n--- Comparison ---");
if (finalPriceA < finalPriceB) {
System.out.println("Shopkeeper A offers a better deal.");
} else if (finalPriceB < finalPriceA) {
System.out.println("Shopkeeper B offers a better deal.");
} else {
System.out.println("Both shopkeepers offer the same final price.");
}
sc.close();
}
}
5. Mr. Agarwal invests certain sum at 5% per annum compound interest for three
years. Write a program in Java to calculate:
(a) the interest for the first year
(b) the interest for the second year
(c) the interest for the third year.
Take sum as an input from the user.
import java.util.Scanner;
public class CompoundInterestBreakup {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
// Output
System.out.printf("\nInterest for the 1st year: ₹%.2f\n", interest1);
System.out.printf("Interest for the 2nd year: ₹%.2f\n", interest2);
System.out.printf("Interest for the 3rd year: ₹%.2f\n", interest3);
}
}
// Constants
double nominalValue = 10.0;
double dividendPercent = 10.0;
int targetShares = 3000;
// Output
System.out.println("Number of shares already held: " + sharesHeld);
System.out.println("Number of shares to be purchased to reach target: " +
sharesToBuy);
sc.close();
}
}
7. Write a program to input time in seconds. Display the time after converting
them into hours, minutes and seconds.
Sample Input: Time in seconds: 5420
Sample Output: 1 Hour 30 Minutes 20 Seconds
import java.util.Scanner;
public class TimeConverter {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
// Conversion
int hours = totalSeconds / 3600;
int remainingSeconds = totalSeconds % 3600;
int minutes = remainingSeconds / 60;
int seconds = remainingSeconds % 60;
// Output
System.out.println(hours+" Hour"+minutes+" Minutes"+seconds+" Seconds");
}
}
8. Write a program to input two unequal numbers. Display the numbers after
swapping their values in the variables without using a third variable.
Sample Input: a = 23, b = 56
Sample Output: a = 56, b = 23
import java.util.Scanner;
// Output
System.out.println("After swapping:");
System.out.println("a = " + a);
System.out.println("b = " + b);
}
}
9. A certain sum is invested at the rate of 10% per annum for 3 years. Write a
program find and display the difference between Compound Interest (CI) and Simple
Interest (SI). Take the sum as an input.
import java.util.Scanner;
// Constants
double R = 10.0; // rate of interest
int T = 3; // time in years
// Calculate difference
double difference = CI - SI;
// Output
System.out.printf("Simple Interest (SI): "+ SI);
System.out.printf("Compound Interest (CI): "+ CI);
System.out.printf("Difference (CI - SI): "+ difference);
sc.close();
}
}
10.A Shopkeeper sells two calculators for the same price. He earns 20% profit on
one and suffers a loss of 20% on the other. Write a program to find and display
his total cost price of the calculators by taking their selling price as input.
import java.util.Scanner;
// Output
System.out.printf("Cost Price of first calculator (20%% profit): "+CP1);
System.out.printf("Cost Price of second calculator (20%% loss): ",+CP2);
System.out.printf("Total Cost Price of both calculators:”+ totalCP);
sc.close();
}
}