Monday, November 9, 2015

JAVA oquestion answer (MATH)

  1. WAP to find volume, curved surface area and the total surface area of a cylinder.

import java.util.*;
class Area
{
  public static void main()
  {
   Scanner sc=new Scanner(System.in);
 int r,h,v,s,t;

 System.out.println(“Enter radius”);
 r= sc.nextInt( );
 System.out.println(“Enter height”);
 h= sc.nextInt( );
double d=Math.PI;

v=d*r*r*h;
s=2*d*r*h;
t=2*d*r*(h+r);

System.out.println(“Volume of a Cylinder is :”+v);
System.out.println(“Curved Surface area of a cylinder is :”+s);
System.out.println(“Total surface area of a cylinder is :”+t);
  }

}

2.WAP to calculate the area of triangle using Heron’s formula.

area =
where  s = (a+b+c)/2

import java.util.*;
class Area
{
  public static void main()
  {
   Scanner sc=new Scanner(System.in);
 int a,b.c,s,area;

 System.out.println(“Enter first side”);
 a= sc.nextInt( );
 System.out.println(“Enter second side”);
 b= sc.nextInt( );
 System.out.println(“Enter third side”);
 c= sc.nextInt( );

 s=(a+b+c)/2;
 area=Math.sqrt(s*(s-a)*(s-b)*(s-c));
 System.out.println(“Area is”+area);
}
}


3.WAP to find the area of right Triangle where ‘B’ is Base, ‘H’ is Height.(Area=1/2*(B*H))

import java.util.*;
class Area
{
  public static void main()
  {
    Scanner sc=new Scanner(System.in);
 int area,b.h;
 System.out.println(“Enter base”);
 a= sc.nextInt( );
 System.out.println(“Enter height”);
 h= sc.nextInt( );

 area=1/2*(h*b);
System.out.println(“Area is “+area);
}
}


4.WAP to convert inches to feet.

import java.util.*;
class Feet
{
  public static void main()
  {
   Scanner sc=new Scanner(System.in);
 int in,f;
System.out.println(“Enter inch”);
 in= sc.nextInt( );
 f=in/12;
System.out.println(“”Feet”+f);
   }
}

5.    WAP to enter the basic salary of an employee and calculate his total salary on the basis of the following allowances and deductutiln.
DA=25% of basic
HRA=15% of basic
PF=8.33% of basic
Net Pay=basic+DA+HRA
Gross pay=Net Pay-PF

import java.util.*;
class Salary
{
  public static void main( )
  {
   Scanner sc=new Scanner(System.in);
double basic,da,hra,pf,netsal,gross_sal;

System.out.println(“Enter basic salary :”);
sal= Double.parseDouble();

da=(25/100)*basic;
hra=(15/100)*basic;
pf=(8.33/100)*basic;
netsal=basic+da+hra;
gross_sal=netsal-pf;

System.out.println(“Total salary is :”+gross_sal);
  }
}

6.    WAP that output the result of the following evaluatutilns based on the number entered by the user :
a.    natural logarithm of the no.
b.    absolute value of no.
c.    square root of the no.
d.    random no. between 0 &1

import java.util.*;
class Number
{
  public static void main( )
  {
   Scanner sc=new Scanner(System.in);
int n,i;

System.out.println(“Enter the number”);
n=sc.nextInt( );

System.out.println(“Log of a number is”+ Math.log(n));
System.out.println(“Absolute value is “+ Math.abs(n));
System.out.println(“Square root is”+ Math.sqrt(n));
System.out.println(“Random no. are”);
for(i=1;i<=10;i++)
{
  System.out.println(Math.random( ));
}
 }
}




7.    WAP to input a degree of an angle and find its sin value.

import java.util.*;
class SinVal
{
  public static void main( )
  {
   Scanner sc=new Scanner(System.in);
double d,R,S;

System.out.println(“Enter the degree :”);
d=Double.parseDouble();
R=(3.14/180)*d;
S=Math.sin(R);

System.out.println(“Sin value :”+S);
              }}


7.    WAP to input an amount and find how many number of Rupees 1000, 500, 100, 50, 20, 10, 5, 2, 1 notes can be there.

import java.util.*;
class Notes
{
  public static void main( )
  {
   Scanner sc=new Scanner(System.in);
int amt,a;
System.out.println(“Enter the amount”);
amt=sc.nextInt( );
a=amt/1000;
if(a!=0)
System.out.println(“Rs. 1000 * ”+a+” = ”+ (1000*a));
a=0;
amt=amt%1000;
a=amt/500;
if(a!=0)
System.out.println(“Rs. 500 * ”+a+” = ”+ (500*a));
a=0;
amt=amt%500;
a=amt/100;
if(a!=0)
System.out.println(“Rs. 100 * ”+a+” = ”+ (100*a));
a=0;
amt=amt%100;
a=amt/50;
if(a!=0)
System.out.println(“Rs. 50 * ”+a+” = ”+ (50*a));
a=0;
amt=amt%50;
a=amt/20;
if(a!=0)
System.out.println(“Rs. 20 * ”+a+” = ”+ (20*a));
a=0;
amt=amt%20;
a=amt/10;
if(a!=0)
System.out.println(“Rs. 10 * ”+a+” = ”+ (10*a));
a=0;
amt=amt%10;
a=amt/5;
if(a!=0)
System.out.println(“Rs. 5 * ”+a+” = ”+ (5*a));
a=0;
amt=amt%5;
a=amt/2;
if(a!=0)
System.out.println(“Rs. 2 * ”+a+” = ”+ (2*a));
a=0;
amt=amt%2;
a=amt/1;
if(a!=0)
System.out.println(“Re. 1 * ”+a+” = ”+ (1*a));
a=0;
 }
}

8.    WAP to find the angle of a sin value.

import java.util.*;
class SinVal
{
  public static void main( )
  {
   Scanner sc=new Scanner(System.in);
double d,R,S;

System.out.println(“Enter the value in Radian :”);
R=Double.parseDouble(obj.readLine( ));
d=(R*180)/3.14;
S=Math.asin(d);
System.out.println(“Angle value is :”+S);
              }
            }


9.    Present value of an annuity is given by the formula :
            P=A[1-1/(1+i)n/i]
Where, A is the amount deposited, I is rate of interest and n is the number of years of investment. WAP to calculate the present value for 80 depositors, for different perutilds of time at 12% rate of interest. [Year 1997]

import java.util.*;
class Annuity
{
  public static void main()
  {
    Scanner sc=new Scanner(System.in);
    double a,n,b,i;

    for( int x=1;x<=80;x++)
    {
      System.out.println(“Enter the amount :”);
      a=Double.parseDouble();
      System.out.println(“Enter the years :”);
      n=Double.parseDouble(obj.readLine());
             
      i=12.0/100.0;
      b=Math.pow((1+i),n)/I;
                   b=1/b;
      b=1-b;
      b=a*b;
      System.out.println(”Interest is :”+b);
   }
  }




No comments:

Post a Comment