Monday, November 9, 2015

java ques








a



  1. WAP to input any number and find the square and cube of that number.

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

System.out.println(“Enter any number :”);
num= sc.nextInt( );

sq=(int)Math.pow(num,2);
cube=(int)Math.pow(num,3);

System.out.println(“Square of the number is :”+sq);
System.out.println(“Cube of the number is :”+cube);
  }
}


  1. WAP to input any two values and swap (exchange) them.

Method I

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

System.out.println(“Enter first value :”);
a= sc.nextInt( );
System.out.println(“Enter second value :”);
b= sc.nextInt( );

c=a;
a=b;
b=c;

System.out.println (“After swapping a =”,a);
System.out.println(“After swapping b =”,b);
  }
}



Method II

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

System.out.println(“Enter first value :”);
a= sc.nextInt( );
System.out.println(“Enter second value :”);
b= sc.nextInt( );

c=a+b;
a=c-a;
b=c-b;

System.out.println(“After swapping a =”,a);
System.out.println(“After swapping b =”,b);
  }
}



Method III : (Without using third variable)

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

System.out.println(“Enter first value :”);
a= sc.nextInt( );
System.out.println(“Enter second value :”);
b= sc.nextInt( );

a=a+b;
b=a-b;
a=a-b;

System.out.println(“After swapping a =”,a);
System.out.println(“After swapping b =”,b);
  }
}

3.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);
   }

}


4.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);
              }
            }

No comments:

Post a Comment