Example SOlution Java Starter booster
Example 1: WAP to find volume of a cube.
import java.io.*;
public class volume
{
public static void main(String args[])throws IOException
{
int L,V;
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.print("ENTER a side of Cube:");
L=Integer.parseInt(br.readLine());
V=L*L*L;
System.out.println("volume="+V);
}
}
Example:2 WAP to find the gross pay of an employee for the following allowances and deduction. Use meaningful variable
Dearness allowance = 25% of basic pay
House rant allowance = 15% of basic pay
Provident fund = 8.33 of basic pay
Net pay = Basic pay + Dearness allowance
+ House rant allowance.
Gross Pay = Net pay - Provident fund
import java.io.*;
class grosspay
{
public static void main (String args[]) throws IOException
{
double basic,HRA,DA, PF, NP,GP ;
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
System.out.println("ENTER THE Basic PAy: ");
basic = Integer.parseInt(br.readLine());
HRA=basic*25/100;
DA=basic*15/100;
PF=basic*8.33/100;
NP=basic+HRA+DA;
GP=NP-PF;
System.out.println("Gross pay Rs..="+GP);
}
}
Example:3
WAP to print Day according to its corresponding Numbers.
import java.io.*;
class day
{
public static void main(String args[])throws IOException
{
InputStreamReader ir = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (ir);
System.out.println("ENTER THE DAY NUMBER");
int D = Integer.parseInt(br.readLine());
switch(D)
{
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("Invalid Number");
}
}
}
Example:4
WAP to check whether triangle is EQUILATERAL , SCALEAN OR IOSCELOUS ?
The three side of triangle entered by user .
class Triangle
{
public static void main(String args[])throws IOException
{
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
System.out.println("ENTER Side A");
int A = Integer.parseInt(br.readLine());
System.out.println("ENTER Side A");
int B = Integer.parseInt(br.readLine());
System.out.println("ENTER Side A");
int C = Integer.parseInt(br.readLine());
if(A==B && B==C)
System.out.println("TRIANGLE IS EQUILATERAL");
else if(A==B||B==C||C==A)
System.out.println ("TRIANGLE IS ISOCELOUS");
else
System.out.println("TRIANGLE IS SCALEAN");
}
}
Example:5
A Cloth showroom has announced the following Festival discount on the purchase of item , based on the total cost of the items purchased :-
Total cost Discount (in Percentage)
Less than 2000 Rs 5%
Rs 2001 to Ra 5000 25%
Rs5001 to Rs 10,000 35%
Above Rs 10,000 50%
WAP to input the total cost and to compute and display the amount to paid
by the customer after availing the discount .
import java.io.*;
class totalcost
{
public static void main (String args[]) throws IOException
{
int TC,D=0,PAY;
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
System.out.println("ENTER THE TOTALCOST");
TC = Integer.parseInt(br.readLine());
if( TC<2000 )
D=TC*5/100;
else if ( TC>=2001 && TC<=5000)
D=TC*25/100;
else if ( TC>=5001 && TC<=10000)
D=TC*35/100;
else if ( TC>=10001)
D=TC*50/100;
PAY=TC-D;
System.out.println("Amount to pay Rs..="+PAY);
}
}
Example:6
A library charges fine for book returned late as per the following
First Five Day 40 Paise per day
Six to Ten day 65 Paise per day
Above ten day 80 Paise per day
Design a program to calculate the fine assuming that a book is returned n days late.
import java.io.*;
class fine
{
public static void main(String args[])throws IOException
{
int fine;
InputStreamReader ir = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (ir);
System.out.println("ENTER No of DAYs to Fine");
int d = Integer.parseInt(br.readLine());
if( d<=5 )
fine=d*40;
else if ( d>5 && d<=10 )
fine=5*40+(d-5)*65;
else if ( d>10 )
fine=5*40+5*65+(d-10)*80;
System.out.println("Fine="+fine);
}
}
Example:7
WAP to calculate and print roots with appropriate messages of quadratic equation .
ax2 + bx +c = 0 The two values of x can be given by
- b + √ b2 -4ac
2a if b2 - 4ac > 0 then roots are real and unequal
if b2 - 4ac = 0 then roots are real and unequal
if b2 - 4ac < 0 then roots are real and unequal
import java.io.*;
class Roots
{
public static void main(String args[])throws IOException
{
double a,b,c,x1,x2,D ;
InputStreamReader ir = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (ir);
System.out.println("ENTER value of a:");
a = Integer.parseInt(br.readLine());
System.out.println("ENTER value of b:");
b = Integer.parseInt(br.readLine());
System.out.println("ENTER vlaue of c:");
c = Integer.parseInt(br.readLine());
D=b*b-4*a*c;
if( D>=0 )
{
x1=(-b+Math.sqrt(D))/2*a;
x2=(-b-Math.sqrt(D))/2*a;
System.out.println("Roots are Real and Unequal");
System.out.println("X1="+x1+"X2="+x2);
}
else if ( D==0 )
{
x1=-b/2*a;
x2=-b/2*a;
System.out.println("Roots are Real and equal");
System.out.println("X1="+x1+"X2="+x2);
}
else
System.out.println("Roots are Imaginary");
}
}
GAilord Software Technologies
Description
this will boost the programming logic and fundamentals
Presentation Transcript
Your Facebook Friends on WizIQ