Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

COMPUTER CH7 UNSOLVED PROGRAMS 1-20

CHAPTER 7 CONDITIONAL STATEMENTS


UNSOLVED PROGRAMS

PROGRAM 1:
import java.util.*;
public class program1
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a1,a2,a3;
System.out.println("Enter the three angles: ");
a1=in.nextInt();
a2=in.nextInt();
a3=in.nextInt();
if(a1+a2+a3==180)
{
System.out.println("Triangle is possible");
if(a1<90 && a2<90 && a3<90)
System.out.println("Acute-angled triangle");
if(a1==90 || a2==90 || a3==90)
System.out.println("Right-angled triangle");
if(a1>90 || a2>90 || a3>90)
System.out.println("Obtuse-angled triangle");
}
else
System.out.println("Triangle not possible");
}
}

P a g e 1 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

PROGRAM 2:
import java.util.*;
public class program2
{
public static void main(String arsgs[])
{
Scanner in=new Scanner(System.in);
double cp,sp,p,pp,l,lp;
System.out.println("Enter the cost price: ");
cp=in.nextDouble();
System.out.println("Enter the selling price: ");
sp=in.nextDouble();
if(sp>cp)
{
p=sp-cp;
pp =p/cp*100.0;
System.out.println("Profit: "+p);
System.out.println("Profit percent: "+pp);
}
else if(sp<cp)
{
l=cp-sp;
lp=l/cp*100.0;
System.out.println("Loss: "+l);
System.out.println("Loss: percent: "+lp);
}
else
System.out.println("Neither profit nor loss");
}
}

P a g e 2 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

PROGRAM 3:
import java.util.*;
public class program3
{
public static void main(String arsgs[])
{
Scanner in=new Scanner(System.in);
int n1,n2,n3;
System.out.println("Enter the three numbers: ");
n1=in.nextInt();
n2=in.nextInt();
n3=in.nextInt();
if(n1!=n2 && n2!=n3 && n3!=n1)
{
if(n1>n2 && n1>n3)
System.out.println("Greatest number: "+n1);
else if(n2>n3 && n2>n1)
System.out.println("Greatest number: "+n2);
else
System.out.println("Greatest number: "+n3);
}
else
System.out.println(“ Numbers are equal”);
}
}

P a g e 3 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

PROGRAM 4:
import java.util.*;
public class program4
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter a number: ");
n=sc.nextInt();
if(n%3==0 && n%5==0)
System.out.println(n+" divisible by 3 as well as 5");
else if(n%3==0 && n%5!=0)
System.out.println(n+" divisible by 3 and not by 5");
else if(n%5==0 && n%3!=0)
System.out.println(n+" divisible by 5 and not by 3");
else
System.out.println(n+" neither divisble by 3 nor by 5");
}
}

PROGRAM 5
import java.util.*;
public class program5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int y;
System.out.println("Enter a year: ");
P a g e 4 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

y=sc.nextInt();
if(y%4==0 && y%100!=0)
System.out.println("It is a Leap year");
else if(y%4==0 && y%100==0)
System.out.println("It is a Century Leap year");
else if(y%4!=0 && y%100==0)
System.out.println("It is a Century year but not a Leap
year");
else
System.out.println("It is a neither a Leap year nor a
Century year");
}
}

PROGRAM 6
import java.util.*;
public class program6
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n1,n2,s1,s2;
System.out.println("Enter the two unequal numbers: ");
n1=sc.nextInt();
n2=sc.nextInt();
s1=(int)Math.sqrt(n1);
s2=(int)Math.sqrt(n2);
if((n1>0 && n2>0 && n1!=n2))
{
if(n1==s1*s1 && n2==s2*s2)

P a g e 5 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

System.out.println("They are perfect square numbers");


else if(n1==s1*s1 && n2!=s2*s2)
{
System.out.println(n1+" is a perfect square
number");
System.out.println(n2+" is not a perfect square
number");
}
else if(n1!=s1*s1 && n2==s2*s2)
{
System.out.println(n1+" is not a perfect square
number");
System.out.println(n2+" is a perfect square
number");
}
}
else if(n1<0 || n2<0)
System.out.print("Square root of negative number can't be
determined");
}
}

PROGRAM 7
import java.util.*;
public class program7
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int a,b,c,sum, s;
System.out.println("Enter the three numbers: ");

P a g e 6 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
sum=a+b+c;
int x= Math.max(a,b);
int big= Math.max(x,c);
int y= Math.min(a,b);
int small= Math.min(y,c);
s= sum-big-small;
System.out.println("Second smallest number is :"+ s);
}
}

PROGRAM 8
import java.util.*;
public class program8_2
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int n1,n2,n3,g=0,s=0;
System.out.println("Enter the three numbers: ");
n1=sc.nextInt();
n2=sc.nextInt();
n3=sc.nextInt();
if(n1>n2 && n1>n3)
g=n1;
if(n2>n1 && n2>n3)
g=n2;
if(n3>n1 && n3>n2)
g=n3;
P a g e 7 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

if(n1<n2 && n1<n3)


s=n1;
if(n2<n1 && n2<n3)
s=n2;
if(n3<n1 && n3<n2)
s=n3;
System.out.println("Greatest Number: "+g);
System.out.println("Smallest Number: "+s);
}
}

PROGRAM 9
import java.util.*;
public class program9
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int d,amt=0;
System.out.println("Enter the distance covered: ");
d=sc.nextInt();
if(d<=5)
amt=100;
if(d>5 && d<=15)
amt=100+(d-5)*10;
if(d>15 && d<=25)
amt=100+10*10+(d-15)*8;
if(d>25)
amt=100+10*10+10*8+(d-25)*5;
P a g e 8 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

System.out.println("Taxi No. : HP 37 1276");


System.out.println("Distance Covered: "+d);
System.out.println("Amount : "+amt);
}
}

PROGRAM 10:
import java.util.*;
public class program10
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int tc;
double dis=0.0;
System.out.println("Enter the total cost: ");
tc=sc.nextInt();
if(tc<=2000)
{
dis=tc*5.0/100.0;
System.out.println("Amount to be paid: "+(tc-dis));
System.out.println("Gift: Calculator");
}
if(tc>=2001 && tc<=5000)
{
dis=tc*10.0/100.0;
System.out.println("Amount to be paid: "+(tc-dis));
System.out.println("Gift: School Bag");
}
if(tc>=5001 && tc<=10000)
P a g e 9 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

{
dis=tc*15.0/100.0;
System.out.println("Amount to be paid: "+(tc-dis));
System.out.println("Gift: Wall Clock");
}
if(tc>10000)
{
dis=tc*20.0/100.0;
System.out.println("Amount to be paid: "+(tc-dis));
System.out.println("Gift: Wrist Watch");
}
}
}

PROGRAM 11
import java.util.*;
public class program11
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int ti,age;
String name;
double tax=0.0;
System.out.println("Enter the name: ");
name=sc.nextLine();
System.out.println("Enter the age: ");
age=sc.nextInt();
System.out.println("Enter the taxable income: ");
ti=sc.nextInt();
if(age<=60)
P a g e 10 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

{
if(ti<=250000)
tax=0.0;
if(ti>250000 && ti<=500000)
tax=(ti-160000)*10.0/100.0;
if(ti>500000 && ti<=1000000)
tax=(ti-500000)*20.0/100.0+3400.0;
if(ti>1000000)
tax=(ti-1000000)*30.0/100.0+9400.0;
}
else
{
System.out.println("Wrong Category");
}
System.out.println("Name: "+name);
System.out.println("Taxable Income: " + ti);
System.out.println(" Income Tax: "+ tax);
}
}

PROGRAM 12
import java.util.*;
public class TermDeposit
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int sum,days;
double matamt=0.0;
System.out.println("Enter the sum to be assured: ");
P a g e 11 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

sum=sc.nextInt();
System.out.println("Enter the number of days: ");
days=sc.nextInt();
if(days<=180)
matamt=sum*5.5/100.0+sum;

if(days>=181 && days<=364)


matamt=sum*7.5/100.0+sum;

if(days==365)
matamt=sum*9.0/100.0+sum;

if(days>365)
matamt=sum*8.5/100.0+sum;

System.out.println("Maturity amount: "+matamt);


}
}

PROGRAM 13
import java.util.*;
public class program13
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String name;
double sum,premium,dis=0.0,com=0.0;
System.out.println("Enter the name of policy holder: ");
name=sc.nextLine();
System.out.println("Enter the sum assured: ");
P a g e 12 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

sum=sc.nextDouble();
System.out.println ("Enter the first annual premium: ");
premium=sc.nextDouble();

if(sum<=100000)
{
dis=premium*5.0/100.0;
com=sum*2.0/100.0;
}
if(sum>=100001 && sum<=200000)
{
dis=premium*8.0/100.0;
com=sum*3.0/100.0;
}
if(sum>=200001 && sum<=500000)
{
dis=premium*10.0/100.0;
com=sum*5.0/100.0;
}
if(sum>500000)
{
dis=premium*15.0/100.0;
com=sum*7.5/100.0;
}
System.out.println("Name of the policy holder\t: "+name);
System.out.println("Sum assured\t\t\t: "+sum);
System.out.println("Premium\t\t\t\t: "+premium);
System.out.println("Discount on the first premium\t: "+dis);
System.out.println("Commission of the agent\t\t: "+com);
}
}
P a g e 13 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

PROGRAM 14
import java.util.*;
public class program14
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int bs;
String name;
double da=0.0,sa=0.0,gs=0.0;
System.out.println("Enter the name: ");
name=sc.nextLine();
System.out.println("Enter the basic salary: ");
bs=sc.nextInt();

if(bs<=10000)
{
da=bs*10.0/100.0;
sa=bs*5.0/100.0;
}
if(bs>=10001 && bs<=20000)
{
da=bs*12.0/100.0;
sa=bs*8.0/100.0;
}
if(bs>=20001 && bs<=30000)
{
da=bs*15.0/100.0;
sa=bs*10.0/100.0;
}
if(bs>=30001)
P a g e 14 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

{
da=bs*20.0/100.0;
sa=bs*12.0/100.0;
}
gs=bs+da+sa;
System.out.println("Name\tBasic\tDA\tSpl. Allowance\tGross
Salary");
System.out.println(name+"\t"+bs+"\t"+da+"\t"+sa+"\t\t"+gs);
}
}

PROGRAM 15
import java.util.*;
public class program15
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int s;
double f,c;
System.out.println("Enter 1 to convert temperature from
Fehrenheit to Celsius");
System.out.println("Enter 2 to convert temperature from
Celsius to Fehrenheit");
System.out.println("Enter your choice: ");
s=sc.nextInt();
switch(s)
{
case 1:
System.out.println("Enter the temperature in Fehrenheit: ");
f=sc.nextDouble();
P a g e 15 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

c=5.0/9.0*(f-32.0);
System.out.println("Temperature in Celsius: "+c);
break;

case 2:
System.out.println("Enter the temperature in Celsius: ");
c=sc.nextDouble();
f=1.8*c+32.0;
System.out.print("Temperature in Fehrenheit: "+f);
break;

default:
System.out.print("Invalid Choice");
}
}
}

PROGRAM 16
import java.util.*;
public class Volume
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int ch;
double v,l,b,h,r;
System.out.println("Enter 1 to calculate volume of cuboid");
System.out.println("Enter 2 to calculate volume of
cylinder");
System.out.println("Enter 3 to calculate volume of cone");

P a g e 16 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

System.out.println("Enter your choice: ");


ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter the length, breadth and height of
cuboid: ");
l=sc.nextDouble();
b=sc.nextDouble();
h=sc.nextDouble();
v=l*b*h;
System.out.println("Volume of cuboid is: "+v);
break;

case 2:
System.out.println("Enter the radius and height of cylinder:
");
r=sc.nextDouble();
h=sc.nextDouble();
v=3.14*r*r*h;
System.out.println("Volume of cylinder is: "+v);
break;

case 3: System.out.print("Enter the radius and height of


cone: ");
r=sc.nextDouble();
h=sc.nextDouble();
v=1.0/3.0*3.14*r*r*h;
System.out.print("Volume of cone is: "+v);
break;

default:
P a g e 17 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

System.out.print("Invalid Choice");
}
}
}

PROGRAM 17
import java.util.*;
public class program17
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int ch,price;
System.out.println("Enter 1 for Ground floor: Kids Wear");
System.out.println("Enter 2 for First floor : Ladies Wear");
System.out.println("Enter 3 for Second floor: Designer Sarees");
System.out.println("Enter 4 for Third floor : Men's Wear");
System.out.println("Enter your choice: ");
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Kids Wear");
System.out.println("Enter the price: ");
price=sc.nextInt();
System.out.println("Name of the Shop: City Mart");
System.out.println("Total amount : "+price);
System.out.println("Visit Again!!!");
break;

case 2:
P a g e 18 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

System.out.println("Ladies Wear");
System.out.println("Enter the price: ");
price=sc.nextInt();
System.out.println("Name of the Shop: City Mart");
System.out.println("Total amount : "+price);
System.out.println("Visit Again!!!");
break;

case 3:
System.out.println("Designer Sarees");
System.out.println("Enter the price: ");
price=sc.nextInt();
System.out.println("Name of the Shop: City Mart");
System.out.println("Total amount : "+price);
System.out.println("Visit Again!!!");
break;

case 4:
System.out.println("Men's Wear");
System.out.println("Enter the price: ");
price=sc.nextInt();
System.out.println("Name of the Shop: City Mart");
System.out.println("Total amount : "+price);
System.out.println("Visit Again!!!");
break;

default:
System.out.println("Invalid Choice");
}
}
}
P a g e 19 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

PROGRAM 18
import java.util.*;
public class program18
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
int ch;
double r1,r2,rs,rp;
System.out.println("Enter 1 for Series Resistance");
System.out.println("Enter 2 for Parallel Resistance");
System.out.println("Enter your choice: ");
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter the value of r1 and r2:");
r1=sc.nextInt();
r2=sc.nextInt();
rs=r1+r2;
System.out.println("Resistance in series is: "+rs);
break;

case 2:
System.out.println("Enter the value of r1 and r2:");
r1=sc.nextInt();
r2=sc.nextInt();
rp=(r1*r2)/(r1+r2);
System.out.println("Resistance in parallel is: +rp);
break;
P a g e 20 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

default:
System.out.println("Invalid Choice");
}
}
}

PROGRAM 19
import java.util.*;
public class program19
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
char ch;
double p,r,t,si,ci;
System.out.println("Enter S for Simple Interest");
System.out.println("Enter C for Compound Interest");
System.out.println("Enter your choice: ");
ch=sc.next().charAt(0);
switch(ch)
{
case 'S':
System.out.println("Enter the value of p : ");
p=sc.nextDouble();
System.out.println("Enter the value of r : ");
r=sc.nextDouble();
System.out.println("Enter the value of t: ");
t=sc.nextDouble();
si=(p*r*t)/100.0;
System.out.println("Simple Interest is: "+si);
P a g e 21 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

break;

case 'C':
System.out.println("Enter the value of p : ");
p=sc.nextDouble();
System.out.println("Enter the value of r : ");
r=sc.nextDouble();
System.out.println("Enter the value of t: ");
t=sc.nextDouble();

ci=p*(Math.pow(1+r/100,t)-1);
System.out.println("Compound Interest is: "+ci);
break;

default:
System.out.println("Invalid Choice");
}
}
}
PROGRAM 20
import java.util.*;
public class program20
{
public static void main(String arsgs[])
{
Scanner sc=new Scanner(System.in);
char type;
String name;
int amt;
double dc=0.0;
System.out.println("Enter the name of the customer: ");
P a g e 22 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

name=sc.nextLine();
System.out.println("Enter the amount of purchase: ");
amt=sc.nextInt();
System.out.println("Enter type of purchase (L for Laptop
and D for Desktop): ");
type=sc.next().charAt(0);
switch(type)
{
case 'L':
if(amt<=25000)
dc=amt*0.0/100.0;

if(amt>=25001 && amt<=50000)


dc=amt*5.0/100.0;

if(amt>=50001 && amt<=100000)


dc=amt*7.5/100.0;

if(amt>100000)
dc=amt*10.0/100.0;
System.out.println("Net amount to be paid by"+ name +"isRs"+ (amt-
dc));
break;

case 'D':
if(amt<=25000)
dc=amt*5.0/100.0;

if(amt>=25001 && amt<=50000)


dc=amt*7.5/100.0;

P a g e 23 | 24
COMPUTER CH7 UNSOLVED PROGRAMS 1-20

if(amt>=50001 && amt<=100000)


dc=amt*10.0/100.0;

if(amt>100000)
dc=amt*15.0/100.0;

System.out.println("Net amount to be paid by


"+name+" is Rs. "+(amt-dc));
break;

default:
System.out.print("Invalid Choice");
}
}
}

P a g e 24 | 24

You might also like