CLASS 9, CHAPTER - 8
PROGRAMMING (Question & Answer)
import [Link];
class Q1_A{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Enter the price of pen : ");
int price = [Link]();
int dis =0;
if(price < 500)
{
[Link]("Pen price is : "+ price);
[Link]("Got a Gift");
}
else
{
dis = price * 25 / 100;
[Link]("Pen price is : "+ price);
[Link]("Discount : "+ dis);
[Link]("Payble amount : "+ (price-dis));
}
}
}
import [Link];
class Q1_B{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Please enter any number : ");
int num = [Link]();
if(num <= 0)
{
[Link]("Please enter any posative number : ");
}
else
{
if(num%2 == 0)
{
[Link]("Number is Even");
}
else
{
[Link]("Number is Odd");
}
}
}
}
import [Link];
class Q1_C{
public static void main()
{
Scanner sc = new Scanner([Link]);
int a, b, c, sum;
[Link]("Enter three angles of a triangle: ");
a = [Link]();
b = [Link]();
c = [Link]();
sum = a+b+c;
if (sum == 180)
[Link]("Triangle is valid");
else
[Link]("Triangle is not valid");
}
}
import [Link];
public class Q1_D{
public static void main() {
Scanner in = new Scanner([Link]);
int dayNum;
[Link]("Enter a day number (1-7): ");
dayNum = [Link]();
switch(dayNum) {
case 1:
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
case 3:
[Link]("Wednesday");
break;
case 4:
[Link]("Thursday");
break;
case 5:
[Link]("Friday");
break;
case 6:
[Link]("Saturday");
break;
case 7:
[Link]("Sunday");
break;
default:
[Link]("Invalid day number.");
break;
}
}
}
import [Link];
class Q1_E{
public static void main() {
Scanner sc = new Scanner([Link]);
[Link]("Enter two integer number : ");
int a = [Link]();
int b = [Link]();
if(a==b)
{
[Link]("Number are twice ");
}
else if(a > b)
{
int square = a*a;
[Link]("Square = "+square);
}
else
{
int cube = b*b*b;
[Link]("Cube "+cube);
}
}
}
import [Link];
class Q1_F{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Enter the marks of Physics : ");
int phy = [Link]();
[Link]("Enter the marks of Chemistry :");
int chem = [Link]();
[Link]("Enter the marks of Math : ");
int math = [Link]();
int totat_marks = phy + chem + math;
float avg = totat_marks / 3;
if(avg >= 90)
{
[Link]("A");
}
else if(avg >= 80)
{
[Link]("B");
}
else if(avg >= 70)
{
[Link]("C");
}
else if(avg >= 60)
{
[Link]("D");
}
else
{
[Link]("F");
}
}
}
import [Link];
class Q1_G{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Enter the customer's name : ");
String c_name = [Link]();
[Link]("Enter the purchase name : ");
int purAmt = [Link]();
float disAmt=0.0f, totalAmt =0.0f;
if(purAmt<=3000)
{
disAmt = purAmt * 5 / 100;
}
else if(purAmt<5000)
{
disAmt = purAmt * 7 / 100;
}
else
{
disAmt = purAmt * 10 / 100;
}
totalAmt = purAmt - disAmt;
[Link]("Customer Name: "+ c_name);
[Link]("Purchase Amount : "+ purAmt);
[Link]("Discount Amount : "+ disAmt);
[Link]("Payble Amount : "+ totalAmt);
}
}
import [Link];
class Q1_G{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Enter the customer's name : ");
String c_name = [Link]();
[Link]("Enter the purchase name : ");
int purAmt = [Link]();
float disAmt=0.0f, totalAmt =0.0f;
if(purAmt<=3000)
{
disAmt = purAmt * 5 / 100;
}
else if(purAmt<5000)
{
disAmt = purAmt * 7 / 100;
}
else
{
disAmt = purAmt * 10 / 100;
}
totalAmt = purAmt - disAmt;
[Link]("Customer Name: "+ c_name);
[Link]("Purchase Amount : "+ purAmt);
[Link]("Discount Amount : "+ disAmt);
[Link]("Payble Amount : "+ totalAmt);
}
}
import [Link];
class Q1_H{
public static void main()
{
Scanner sc = new Scanner([Link]);
double disAmt = 0.0;
[Link]("Enter the bill amount : ");
int billAmt = [Link]();
[Link]("1. Credit Card. \n2. Debit Card. \n3. E-Wallet. \n4. Cash. ");
[Link]("Mode of payment : ");
int mode = [Link]();
if(mode == 1)
{
disAmt = (billAmt * 1.5) / 100;
[Link]("Mode of payment: Credit Card ");
[Link]("Payble Amount: "+(billAmt-disAmt));
}
else if(mode == 2)
{
disAmt = 10;
[Link]("Mode of payment: Debit Card ");
[Link]("Cash Back: "+disAmt);
[Link]("Payble Amount: "+(billAmt-disAmt));
}
else if(mode == 2)
{
disAmt = 20;
[Link]("Mode of payment: E-Wallet ");
[Link]("Cash Back: "+disAmt);
[Link]("Payble Amount: "+(billAmt-disAmt));
}
else if(mode == 4)
{
disAmt = 0;
[Link]("Mode of payment: Cash ");
[Link]("Discount : "+disAmt);
[Link]("Payble Amount: "+(billAmt-disAmt));
}
else
{
[Link]("Invalid Choice! ");
}
}
}
import [Link];
class Q1_I{
public static void main()
{
Scanner sc = new Scanner([Link]);
double billAmt = 0.0;
[Link]("Enter the number of calles : ");
int calles = [Link]();
if(calles<=50)
{
billAmt = 100;
}
else if(calles <= 100)
{
billAmt = 100 + (calles - 50) * 0.88;
}
else if(calles <= 200)
{
billAmt = 100 + (50*0.80) + (calles - 100) * 0.60;
}
else
{
billAmt = 100 + (50*0.80) + (100*0.60) + (calles - 200) * 40;
}
[Link]("Number of Calles : "+ calles);
[Link]("Total Bill Amount to be paid : "+billAmt);
}
}
import [Link];
class Q1_H{
public static void main() {
Scanner sc = new Scanner([Link]);
int product;
double commission = 0.0;
String gift = "";
[Link]("Enter the number of products : ");
product = [Link]();
if(product <= 50)
{
commission = product * 5 / 100;
gift = "A Parker Pen";
}
else if(product <= 75)
{
commission = product * 7.5 / 100;
gift = "A Micro SD Card";
}
else if(product <= 100)
{
commission = product * 10 / 100;
gift = "A Mobile";
}
else
{
commission = product * 15 / 100;
gift = "A Laptop";
}
[Link]("Number of sold products : "+product);
[Link]("Commission : "+commission);
[Link]("Gift : "+gift);
}
}
____________________________
import [Link];
class Q1_I{
public static void main() {
Scanner sc = new Scanner([Link]);
int salary;
double tax = 0.0;
[Link]("Enter annual taxable income : ");
salary = [Link]();
if(salary <=100000)
{
tax = 0.0;
}
else if(salary <=150000)
{
tax = (salary-100000) * 0.10;
}
else if(salary <=250000)
{
tax = 5000+(50000*0.10)+(salary-150000)*0.20;
}
else
{
tax = 25000+(50000*0.10)+(100000*0.20)+(salary-250000)*0.30;
}
[Link]("Annual Salary : "+salary);
[Link]("Tax amount : "+tax);
[Link]("Total Salary : "+(salary - tax));
}
}
import [Link];
class Q1_J{
public static void main()
Scanner sc = new Scanner([Link]);
[Link]("Enter any letter : ");
char ch = [Link]().charAt(0);
if((ch=='a') || (ch=='e') || (ch=='i') || (ch=='o') || (ch=='u') || (ch=='A') || (ch=='E') || (ch=='I') ||
(ch=='O') || (ch=='U'))
[Link]("Vowels");
else
[Link]("Consonent");
import [Link];
class Q2_A{
public static void main()
{
Scanner sc = new Scanner([Link]);
int r,h;
[Link]("1. Volume of Sphere. \n2. Volume of Cylinder. \n3. Volume of cone");
[Link]("Enter your choice");
int ch = [Link]();
switch(ch)
{
case 1:
[Link]("Enter the value of radius : ");
r = [Link]();
double sphere = 4 / (3 * [Link] * [Link](r,3));
[Link]("Volume of Sphere : "+sphere);
break;
case 2:
[Link]("Enter the value of radius : ");
r = [Link]();
[Link]("Enter the value of height : ");
h = [Link]();
double cylinder = [Link] * [Link](r,2) * h;
[Link]("Volume of Sphere : "+cylinder);
break;
case 3:
[Link]("Enter the value of radius : ");
r = [Link]();
[Link]("Enter the value of height : ");
h = [Link]();
double cone = ([Link] * [Link](r,2) * h)/3;
[Link]("Volume of Sphere : "+cone);
break;
default:
[Link]("Invalid Key Pressed!");
break;
}
}
}
___________________________________
import [Link];
public class Q2_B
{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Type 1 to convert from Fahrenheit to Celsius");
[Link]("Type 2 to convert from Celsius to Fahrenheit");
int choice = [Link]();
double ft = 0.0, ct = 0.0;
switch (choice) {
case 1:
[Link]("Enter temperature in Fahrenheit: ");
ft = [Link]();
ct = 5 / 9.0 * (ft - 32);
[Link]("Temperature in Celsius: " + ct);
break;
case 2:
[Link]("Enter temperature in Celsius: ");
ct = [Link]();
ft = 1.8 * ct + 32;
[Link]("Temperature in Fahrenheit: " + ft);
break;
default:
[Link]("Incorrect Choice");
break;
}
}
}
______________________________________
import [Link];
public class Q2_C {
public static void main() {
Scanner sc = new Scanner([Link]);
int num,i;
[Link]("1. Prime Number \n2. Factorial");
int choice = [Link]();
switch(choice)
{
case 1:
int count=0;
[Link]("Enter any Number : ");
num = [Link]();
for(i=2; i<num; i++)
{
if(num%i == 0)
{
count++;
break;
}
}
if(count == 0)
{
[Link]("This is a Prime Number");
}
else
{
[Link]("This is not a Prime Number");
}
break;
case 2:
[Link]("Enter any Number : ");
num = [Link]();
long factorial = 1;
for(i = 1; i <= num; ++i)
{
factorial *= i;
}
[Link]("Factorial =" + factorial);
break;
}
}
}
______________________________________
import [Link];
class Q2_D{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("1. Square Root of 9. \n2. Absolute Value of 126.4. \n3. Smallest value
of 56.7. \n4. Print any value from 0 and 1");
[Link]("Enter your choice");
int ch = [Link]();
switch(ch)
{
case 1:
[Link]("Square Root : "+[Link](9));
break;
case 2:
[Link]("Absolute Value : "+[Link](126.4));
break;
case 3:
[Link]("Smallest Value : "+[Link](56.7));
break;
case 4:
[Link]("Value between 0 and 1 : "+[Link]());
break;
default:
[Link]("Invalid Key Pressed!");
break;
}
}
}
___________________________________
import [Link];
class Q2_E{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("1. Volume of Sphere. \n2. Volume of Cylinder. \n3. Volume of cone");
[Link]("Enter your choice");
int ch = [Link]();
switch(ch)
{
case 1:
[Link]("Enter the value of lenghth and Breadth : ");
int l = [Link]();
int b = [Link]();
double aor = l * b;
[Link]("Area of Rectangle : "+aor);
break;
case 2:
[Link]("Enter the value of side : ");
int side = [Link]();
double aos = [Link](side,2);
[Link]("Area of square : "+aos);
break;
case 3:
[Link]("Enter the value of radius : ");
int r = [Link]();
double aoc = [Link] * [Link](r,2);
[Link]("Are of Square : "+aoc);
break;
default:
[Link]("Invalid Key Pressed!");
break;
}
}
}