If Else Programming
If Else Programming
PROGRAMMING
JAVA
JAVA CLASSES
CLASSES
ICSE
ICSE AND
AND ISC
ISC
BOARD
BOARD
M:
M: 7017669878
7017669878
PROGRAMMERS POINT
Computer Application / Computer Science (For ICSE/ISC/CBSE Board)
Add: Madhav Kunj, Opp. SEA TV office, Behind Diamond Gym, Agra
Behind Kundkund Dharmshala, Opp. Collectorate Office, Agra
PEC Coaching centre, Sector- 4, Avas vikas Colony, Sikandra, Agra Mob: 827365168
Ankuram Education, Punchwati (Parasnath) Near Shankar Green, Fatehabad Road, 5
701795418
4
Class : X IF ELSE PROGRAMMING
1. WAP to print the larger of two numbers entered from the keyboard.
class i1
{
public static void main(int a,int b)
{
if(a>b)
System.out.println("Greatest number is "+a);
else
System.out.println("Greatest number is "+b);
}
}
2. WAP to accept a number from keyboard and check whether it is a positive number, negative
number or zero .print suitable message.
import java.util.*;
class i2
{
public static void main()//n=0
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter any number");
n=sc.nextInt();
if(n>0)
System.out.println("positive number is "+n);
else if(n<0)
System.out.println("Negative number is "+n);
else if(n==0)
System.out.println("Number is Zero");
}
}
class i3
{
public static void main(int n)//n=7
{
if(n%2==0)
System.out.println("it is a Even number");
else
System.out.println("it is a Odd number");
}
}
4. A voter is eligible to vote the election held in his city if his age is at least 18 yrs. Define a class
Eligibility test that checks for the eligibility of a voter.
class i4
{
public static void main(int age)
{
if(age>=18)
System.out.println("Voter is eligible to vote");
else
System.out.println("voter is not eligible to vote");
}
}
class i5
{
public static void main(int sales)
{
double comm=0.0;
if(sales<5000)
comm=sales*3.0/100.0;
else if(sales>=5000 && sales<=10000)
comm=sales*8.0/100.0;
else if(sales>10000)
comm=sales*10.0/100.0;
System.out.println("commission of salesman = "+comm);
}
}
class i6
{
public static void main(int day)
{
switch(day)
{
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
default:
System.out.println("Wrong choice");
}
}
}
class i7
{
public static void main(int month)
{
switch(month)
{
case 1:
System.out.println("jan");
break;
case 2:
System.out.println("feb");
break;
case 3:
System.out.println("march");
break;
.
.
.
case 12:
System.out.println("Dec");
default:
System.out.println("Wrong choice");
}
}
}
8. Define a java class maximum to print the largest out of the three numbers accepted from the user.
class i8
{
public static void main(int a,int b,int c)
{
if(a>b && a>c)
System.out.println("Greatest number is "+a);
else if(b>a && b>c)
System.out.println("Greatest number is "+b);
else if(c>a && c>b)
System.out.println("Greatest number is "+c);
}
}
class i9
{
public static void main(int a,int b)
{
if(a%b==0)
System.out.println(" a is divisible by b");
else
System.out.println(" a is not divisible by b");
}
}
10. An electricity board charges the bill depending on the number of units consumed as follows.
Units Charge
First 100 units 40 ps/per unit
Next 200 units 60 ps/per unit
Above 300 Rs 1 per unit
class i10
{
public static void main(int units)
{
double bill=0.0;
if(units<=100)
bill=units*.40;
else if(units>=101 && units<=300)
bill=100*.40+(units-100)*.60;
else if(units>300)
bill=100*.40+200*.60+(units-300)*1;
System.out.println("Electricity Bill = "+bill);
}
}
11. WAP class Leap to accept an year and check if it a leap year or not.
class i11
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int year;
System.out.println("Enter any year");
year = sc.nextInt();
if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))
System.out.format(year +" is Leap year");
}
else
}
COMPUTER CODING CLASSES 7017669878
System.out.format(ye
ar +" is not Leap
year");
import java.util.*;
class i12
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int A,B,C;
System.out.println("Enter first side of triangle");
A=sc.nextInt();
System.out.println("Enter second side of triangle");
B=sc.nextInt();
System.out.println("Enter third side of triangle");
C=sc.nextInt();
if(A==B && B==C && C==A)
System.out.println("Equilateral Triangle");
else if(A==B || B==C || C==A)
System.out.println("Isosceles Triangle");
else if(A!=B && B!=C && C!=A)
System.out.println("Scalene Triangle");
}
}
13. WAP to compute the amount that a customer pays for the taxi that he hires based on the following
condition:
Kms Travelled Amount per km
First 10 kms 25
Next 20 kms 10
Next 40 kms 15
Above 70 kms 12
Input the customer name, the taxi number and the number of kilometers travelled by him.
class i13
{
public static void main(String name,int taxino,int km)
{
int Fare=0;
if(km<=10)
Fare=km*25;
else if(km>10 && km<=30)
Fare=10*25+(km-10)*10;
else if(km>30 && km<70)
Fare=10*25+20*10+(km-30)*15;
else
Fare=10*25+20*10+40*15+(km-70)*12;
System.out.println("Fare of taxi = "+Fare);
COMPUTER CODING CLASSES 7017669878
}
}
import java.util.*;
class i14
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int amount,choice;
System.out.println("Enter the purchasing amount");
amount=sc.nextInt();
System.out.println("Enter your choice");
System.out.println("case 1 for mill cloth ");
System.out.println("case 2 for Handloom item");
choice=sc.nextInt();
double dis=0.0;
switch(choice)
{
case 1:
if(amount<1000)
dis=amount*2.0/100.0;
else if(amount>=1000 && amount<=5000)
dis=amount*20.0/100.0;
else
dis=amount*40.0/100.0;
System.out.println("Discount on Mill Cloth = "+dis);
System.out.println("Net amount to paid = "+(amount-dis));
break;
case 2:
if(amount<1000)
dis=amount*5.0/100.0;
else if(amount>=1000 && amount<=5000)
dis=amount*25.0/100.0;
else
dis=amount*50.0/100.0;
System.out.println("Discount on Handloom Item = "+dis);
System.out.println("Net amount to paid = "+(amount-dis));
break;
default:
System.out.println("Wrong choice");
class i15
{
public static void main(int A,int B,int C)
{
if(A<90 && B<90 && C<90)
System.out.println("Acute triangle");
16. WAP to print any no check & print whether it is BUZZ no or not.
it is divided by 7 and remainder is 7.
class i16
{
public static void main(int n)
{
if(n%7==0 || n%10==7)
System.out.println("Buzz number");
else
System.out.println("not a Buzz number");
}
}
class i17
{
public static void main(int n)
{
if(n%2==0 && n%3==0)
System.out.println("Appropriate number");
else
System.out.println("Not an Appropriate number");
class i18
{
public static void main(int income)
{
double tax=0.0;
if(income<=100000)
tax=income*0.0/100.0;
else if(income>=100001 && income<=150000)
tax=income*10.0/100.0;
else if(income>150000)
tax=income*30.0/100.0;
19. A cloth showroom has announced the following festival discount on the total cost of item purchased,
WAP to input the total cost and display the amount to be paid by the purchaser.
Total Cost Discount
upto 2000 15%
>2000 to 5000 25%
> 5000 to 10000 35%
>10000 50%
import java.util.*;
class i19
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int cost;
System.out.println("Enter the cost");
cost=sc.nextInt();
double dis=0.0;
System.out.println("Discount = "+dis);
}
}
20. WAP to input CP & SP of an article calculates & print its Profit% or loss% .if CP & SP are equal
then print no profit no loss.
class i20
{
public static void main(int sp,int cp)
{
int p,l;
double pp,lp;
if(sp>cp)
{
p=sp-cp;
pp=(p*100)/cp;
System.out.println("Profit percent = "+pp);
}
else
{
l=cp-sp;
lp=(l*100)/cp;
System.out.println("Loss percent = "+lp);
}
}
}
21. WAP to input total no of monthly calls, calculate & print the monthly tel. bill as given criteria.
No of Calls Call Rate
First 100 80 ps./call
Next 200 60 ps./call
Beyond 300 40 ps./call
class i21
System.out.println("Bil = "+bill);
}
}
22. Define a class to accept sales of a salesman and print his commission according to the following
criteria.
Sales(s) Commission
50000 onward s 15%
33000 <=s <50000 9%
18000 <=s <33000 6%
6000 <=s <18000 3%
0 <=s <6000 0%
import java.util.*;
class i22
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int sales;
double comm=0.0;
System.out.println("Enter the sales of salesman");
sales=sc.nextInt();
if(sales>=50000)
comm=sales*15.0/100.0;
else if(sales>=33000 && sales<50000)
comm=sales*9.0/100.0;
else if(sales>=18000 && sales<33000)
comm=sales*6.0/100.0;
else if(sales>=6000 && sales<18000)
comm=sales*3.0/100.0;
else if(sales>0 && sales<6000)
comm=0.0;
24. An electricity board charges the following rates to domestic users to discourage large consumption of
electricity.
Units Charge
First 100 units 40 ps/per unit
Next 200 units 60 ps/per unit
Above 300 Rs 1 per unit
If the bill is above Rs. 1000 upto Rs. 2000 an extra surcharge of 10% is added. If the bill amount is above
Rs. 2000 a surcharge of 20% is added.
Write a program to enter the units consumed and print the bill in the proper format.
class i24
{
public static void main(int units)
{
COMPUTER CODING CLASSES 7017669878
double bill=0.0;
if(units<=100)
bill=units*.40;
25. An employee is entitled to pay an income tax based on his gross annual income as follows:
Annual gross income Annual tax deduction
Less than or equal to Rs. 100000 0%
100001 to 500000 Rs. 1000 + 10% of income exceeding Rs. 100000
500001 to 800000 Rs. 5000 + 20% of income exceeding Rs. 500000
> 800000 Rs. 10000 + 30% of income exceeding Rs. 800000
Write a program to accept the monthly salary of a person and print the annual tax paid by the salaried
person.
class i25
{
public static void main(int Msalary)
{
double tax=0.0;
int Asalary=Msalary*12;
if(Asalary<=100000)
tax=0.0;
else if(Asalary>=100001 && Asalary<=500000)
tax=1000+(Asalary-100000)*10.0/100.0;
else if(Asalary>=500001 && Asalary<=800000)
tax=5000+(Asalary-500000)*20.0/100.0;
else
tax=10000+(Asalary-800000)*30.0/100.0;
System.out.println("Tax of Employee = "+tax);
}
}
26. Write a program to enter item no., quantity purchased and rate. Calculate the total purchase price
and print it with the gifts. The to be the customers are given in the following manner:
27. A library charges fine according to the number of a book is returned late, according to the following
criteria:
Days Fine per day
First 10 days Rs. 1
Next 10 days Rs. 1.50
Above 20 days Rs. 2.00
WAP to enter the number of days a book is returned late and print the fine to be paid.
class i27
{
public static void main(int days)
{
double fine=0.0;
if(days<=10)
fine=days*1;
else if(days>=11 && days<=20)
fine=10*1+(days-10)*1.50;
else if(days>=20)
fine=10*1+10*1.50+(days-20)*2.00;
System.out.println("Fine of student ="+fine);
}
}
28. A cloth showroom offers discounts in its regular stock clearance sale as per follows:
Amount of purchase Discount in %
Cloth material Readymade garments
Less than or equal to 500 3% 2%
Greater than 500 upto 2000 8% 5%
Greater than 2000 upto 5000 12% 10%
Greater than 5000 20% 15%
Write a java program to compute the net amount paid by the customer. Assume all required
values to be inputted by the user. Make use of if and switch structure.
import java.util.*;
class i29
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int amount,choice;
double dis=0.0;
System.out.println("Enter the purchasing amount");
amount=sc.nextInt();
switch(choice)
{
case 1:
if(amount<=20000)
dis=amount*3.0/100.0;
else if(amount>20000 && amount<=50000)
dis=amount*8.0/100.0;
else if(amount>50000 && amount<=100000)
dis=amount*12.0/100.0;
else
dis=amount*20.0/100.0;
System.out.println("Discount on Laptop = "+dis);
System.out.println("Net amount to paid = "+(amount-dis));
break;
COMPUTER CODING CLASSES 7017669878
case 2:
if(amount<=20000)
dis=amount*2.0/100.0;
else if(amount>20000 && amount<=50000)
dis=amount*5.0/100.0;
else if(amount>50000 && amount<=100000)
dis=amount*10.0/100.0;
else
dis=amount*15.0/100.0;
System.out.println("Discount on Desktop = "+dis);
System.out.println("Net amount to paid = "+(amount-dis));
break;
default:
System.out.println("Wrong choice");
}
}
}
30.Using a switch statement, write a menu driven program to convert a given temperature from Fahrenheit
to Celsius and vice versa. For an incorrect choice, an appropriate error message should be displayed:
(Hint: C=5/9 *(F-32) and F=1.8*C+32)
import java.util.*;
class i30
{
public static void main()
{
Scanner sc=new Scanner(System.in);
double F,C;
int choice;
System.out.println("Enter your choice");
System.out.println("Case 1 for convert celcius to fahrenheit");
System.out.println("Case 2 for convert fahrenheit to celcius");
choice=sc.nextInt();
switch(choice)
{
case 1:
System.out.println("Enter the temp. in celcius");
C=sc.nextDouble();
F=1.8*(C+32);
COMPUTER CODING CLASSES 7017669878
System.out.println("Temp. in Fahrenheit =
"+F); break;
default:
System.out.println("Wrong choice");
}
}
}