0% found this document useful (0 votes)
1 views

INDEX

Uploaded by

youvaantulsian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

INDEX

Uploaded by

youvaantulsian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

INDEX

SL. PROGRAM NAME PG. NO.


NO.
1. Take two values as input and print their sum and 1-2
division

2. Write a program in java to display area and 3-4


perimeter of a rectangle taking length and breadth
from user

3. Take cost price of a book as input. Print sp of two 5-6


dozen of book when 6% discount is allowed

4. Take marks in 5 subject as input and print the total 7-8


and average marks

5. Take a number as input and if it is odd then check 9-11


last digit is prime or not. If it is even then check
perfect square or not

6. Write a program to input three unequal numbers 12-14


and display the second smallest number using
scanner class.

7. Write a program to calculate the taxable according 15-17


to the distance travelled.

8. Take name and price as input and display name 18-20


and calculate net price to be paid after the
discount

9. Calculating Area of a rectangle, square and circle 21-23


as per choice

10. Discount calculation on the basis of purchase 24-26


category i.e. laptop or desktop as per choice
11. Acknowledgment 27
QUESTION 1:
Take two values as input and print their sum and division

SOURCE CODE:

import java.util.*;
class sum
{
void main()
{
double a,b,s=0.0,d=0.0;
Scanner sc=new Scanner(System.in);
System.out.println("enter two values");
a=sc.nextInt();
b=sc.nextInt();
s=a+b;
System.out.println("sum="+s);
d=a/b;
System.out.println("division="+d);
}
}

OUTPUT:
enter two values
20
30
sum=50.0
division=0.6666666666666666

QUESTION 2:
Write a program in java to display area and perimeter of a
rectangle taking length and breadth from user
SOURCE CODE:

import java.util.*;
class Rectangle
{
void main(){
double length,breadth,area,peri;
Scanner sc=new Scanner(System.in);
System.out.println("Enter length and breadth ");
length=sc.nextDouble();
breadth=sc.nextDouble();
area=length*breadth;
peri=2*(length+breadth);
System.out.println("Area of Rectangle "+area);
System.out.println("Perimeter of Rectangle "+peri);
}
}

OUTPUT:

Enter length and breadth


20
30
Area of Rectangle 600.0
Perimeter of Rectangle 100.0

QUESTION 3:

Take cost price of a book as input. Print sp of two dozen of


book when 6% discount is allowed
SOURCE CODE:

import java.util.*;
class Cost
{
void main()
{
double cp,sp,d,tp;
Scanner sc=new Scanner(System.in);
System.out.println("Enter cost price ");
cp=sc.nextDouble();
d=cp*6.0/100;
sp=cp-d;
tp=sp*24;
System.out.println("Total price ="+tp);
}
}

OUTPUT:

Enter cost price


30000
Total price =676800.0
QUESTION 4:

Take marks in 5 subject as input and print the total and average
marks

SOURCE CODE:
import java.util.*;
class total
{ void main()
{
double m1,m2,m3,m4,m5,s=0,avg;
Scanner sc=new Scanner(System.in);
System.out.println("Enter marks in five subjects ");
m1=sc.nextDouble();
m2=sc.nextDouble();
m3=sc.nextDouble();
m4=sc.nextDouble();
m5=sc.nextDouble();
s=m1+m2+m3+m4+m5;
avg=s/5.0;
System.out.println("total marks "+s);
System.out.println("average "+avg);
}
}

OUTPUT:

Enter marks in five subjects


90
88
85
84
79
total marks 426.0
average 85.2

QUESTION 5:
Take a number as input and if it is odd then check last digit is
prime or not. If it is even then check perfect square or not

SOURCE CODE:
import java.util.*;
class Check1
{
void main()
{
int a,b;
int k;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a value ");
a=sc.nextInt();
if(a%2==1)
{
int ld=a%10;
if(ld==3||ld==5||ld==7)
System.out.println("Odd Number and Last digit is prime ");
else
System.out.println("Odd Number and Last digit is not prime ");
}
if(a%2==0)
{
k=(int)Math.sqrt(a);
if(k*k==a)
System.out.println("even number and Perfect square "+a);
else
System.out.println("even number and not a perfect square"+a);
}
}
}
OUTPUT:

Enter a value
23
Odd Number and Last digit is prime

Enter a value
22
even number and not a perfect square22
QUESTION 6:

Write a program to input three unequal numbers and display


the second smallest number using scanner class.

SOURCE CODE:

import java.util.*;
class Smallest
{
void main ()
{
Scanner sc = new Scanner(System.in);
int a,b,c;
System.out.println ("Enter Three Numbers");
a= sc.nextInt();
b= sc.nextInt();
c= sc.nextInt();
if(a<b && a<c)
{
if(b<c)

System.out.println("The second smallest number:"+b);


else
System.out.println("The second smallest number:"+c);
}
if(b<c && b<a)
{
if(c<a)
System.out.println("The second smallest number:"+c);
else
System.out.println("The second smallest number:"+a);
}
if(c<a && c<b)
{
if(a<b)
System.out.println("The second smallest number :"+a);
else
System.out.println("The second smallest number :"+b);
}
}
}

OUTPUT:

Enter Three Numbers


10
20
30
The second smallest number:20
QUESTION 7:

Write a program to calculate the taxable according to the


distance travelled.

Distance Fare
Upto 25 Rs5/km
For next 10 Rs 7/km
For next 25 Rs 9/km
For next 10 Rs 10/km
>70 Rs 15/km
SOURCE CODE:

import java.util.*;
class distance
{void main()
{
double d,f=0.0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter passenger name");
String name=sc.next();
System.out.println("enter distance ");
d=sc.nextDouble();
if(d<=25){

f=d*5;}
else if(d>25 && d<=35)
{f=25*5+(d-25)*7;}
else if(d>35 && d<=60)
{f=25*5+10*7+(d-35)*9;
}
else if(d>60 && d<=70)
{f=25*5+10*7+25*9+(d-60)*10;
}
else if(d>70)
{f=25*5+10*7+25*9+10*10+
(d-70)*15;
}
System.out.println("total fare "+f);
}
}

OUTPUT:

enter distance
200
Enter passenger name
youvaan
Passenger name youvaan
total fare 2470.0
QUESTION 8:

Take name and price as input and display name and calculate
net price to be paid after the discount

Price Discount
Upto 2000 5%
2001 to 4000 6.5%
>4000 8%

SOURCE CODE:

import java.util.*;

class Disc2 {

void main(){
double p=0.0,d=0.0,np=0.0;

String name;

Scanner sc=new Scanner(System.in);

System.out.println("enter name and price");

name=sc.next();

p=sc.nextDouble();

if(p<=2000){
d=5.0/100*p;}

else if(p>2000 && p<=4000){

d=6.5/100*p;}

else{

d=8.0/100*p;}

np=p-d;

System.out.println("name="+name);

System.out.println("net price ="+np);

}
}
OUTPUT:

enter name and price


Youvaan
30000
name=Youvaan
net price =27600.0
QUESTION 9:
Write a program in java to calculate area of the following as per
users choice
1 Perimeter of rectangle
2 Perimeter of square
3 Circumference of circle

SOURCE CODE:
import java.util.*;

class Menu1
{
void main()
{
Scanner sc=new Scanner(System.in);

char ch;
double s,l,b,a,r;
System.out.println("enter 'r' for area of rectangle");
System.out.println(" enter 's' for area of square");
System.out.println(" enter 'c' for area of circle");
System.out.println(" enter choice");
ch=sc.next().charAt(0);
switch(ch)
{
case 'r':
System.out.println("enter length and breadth");
l=sc.nextDouble();
b=sc.nextDouble();
a=l*b;
System.out.println("area="+a);
break;
case 's':
System.out.println("enter side of a square");
s=sc.nextDouble();
a=s*s;
System.out.println("area="+a);

break;
case 'c':
System.out.println("enter radius of circle");
r=sc.nextDouble();
a=3.14*r*r;
System.out.println("area="+a);
break;
default:
System.out.println("invalid choice");
}

}
}
OUTPUT:
enter 'r' for area of rectangle
enter 's' for area of square
enter 'c' for area of circle
enter choice
r
enter length and breadth
9
10
area=90.0

enter 'r' for area of rectangle


enter 's' for area of square
enter 'c' for area of circle
enter choice
c
enter radius of circle
45
area=6358.500000000001
QUESTION 10:
Enter purchase amount and criteria (L for laptop and D for
desktop and calculate net amount after the discount.
purchase amount discount on laptop discount on
desktop
* upto 25000 0% 5.0%
* 25001 to 57000 5.0% 7.5%
* >57000 7.5% 10%

use Menu driven or switch case

SOURCE CODE:
import java.util.*;
class Menu2
{
void main()
{
double p,d,np=0.0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter L for laptop D for desk top \n Enter
choice");
char ch=sc.next().charAt(0);
switch(ch)
{case 'L':
System.out.println("Enter purchase amount ");
p=sc.nextDouble();
if(p<=25000)
d=0;
else if(p>25000 && p<=57000)
d=5.0/100*p;
else
d=7.5/100*p;
np=p-d;
System.out.println("net amount to be paid for laptop "+np);
break;
case 'D':
System.out.println("Enter purchase amount ");
p=sc.nextDouble();
if(p<=25000)
d=5.0/100*p;
else if(p>25000 && p<=57000)
d=7.5/100*p;
else
d=10.0/100*p;
np=p-d;
System.out.println("net amount to be paid for desktop "+np);
break;
default:
System.out.println("wrong choice ");
}
}
}

OUTPUT:

Enter L for laptop D for desk top


Enter choice
L
Enter purchase amount
25000
net amount to be paid for laptop 25000.0

Enter L for laptop D for desk top


Enter choice
D
Enter purchase amount
25000
net amount to be paid for desktop 23750.0
ACKNOWLEDGMENT

I would like to express my special thanks of gratitude to my


Computer Applications Teacher, “Mr. D. Das”, who gave
me the golden opportunity to do this wonderful project on the
topic, “10 programs in java.” While researching I came across
many new things for which I am really grateful for. I would also
like to thank my parents for providing me with all the materials
required for the completion of this project.

You might also like