Sunday 16 August 2015

Temperature of city in Fahrenheit degrees is input through the keyboard.WAP in java to convert this temperature into Centigrade degrees.

//Conversion of temperature from Fahrenheit to centigrade degrees

import java.util.Scanner;

class Temperature {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter temperature in Fahrenheit:");
float F=sc.nextFloat();

System.out.println("Temperature in Centigrade degrees:"+((5/9.0f)*(F-32)));
}

}

WAP in java to swap 2 nos without using 3rd variable.

//Swap 2 nos without the use of 3rd variable.

import java.util.Scanner;

public class Swap {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a,b;

System.out.println("Enter 2 nos:");
a=sc.nextInt();
b=sc.nextInt();

System.out.println("Before Swapping...a="+a+" b="+b);
a=a+b;
b=a-b;
a=a-b;

System.out.println("After swapping...a="+a+" b="+b);
}
}

WAP in java to enter 6 subject marks of a student and calculate total and percentage of of a student.

//Calculate total and percentage of Student for 6 subjects

import java.util.Scanner;

class Student {

public static void main(String args[])
{
int m1,m2,m3,m4,m5,m6,t;
                float p;

               Scanner sc=new Scanner(System.in);
System.out.println("Enter marks for 6 subject:");
m1=sc.nextInt();
m2=sc.nextInt();
m3=sc.nextInt();
m4=sc.nextInt();
m5=sc.nextInt();
m6=sc.nextInt();


                if(m1<0 || m2<0 || m3<0 || m4<0 || m5<0 || m6<0 ||m1>100 || m2>100 || m3>100 || m4>100                       || m5>100 || m6>100)
 System.out.println("Invalid Input");
else
               {
       t=m1+m2+m3+m4+m5+m6;
       p=t/6;

       System.out.println("Total:"+t+" Percentage:"+p);
        }

}
}

WAP in java to check character entered is a special symbol or not.

//Check character is special symbol or not

import java.util.Scanner;

public class Spcl_Symbol {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a character:");
char x=sc.next().charAt(0);

if(x>=32 && x<=47)
System.out.println("It is a Special Symbol.");
else
System.out.println("It is not a Special Symbol.");
}
}

WAP in java to accept principal amount,rate of interest and year through the keyboard and find out simple interest.

//Calculate Simple Interest

import java.util.Scanner;

class SI {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter respectively principle,rate of interest(in %) and duration(in years):");
long p=sc.nextLong();
float r=sc.nextFloat();
float n=sc.nextFloat();

float si=(p*n*r)/100;

System.out.println("Simple Interest:"+si);
}

}

WAP in java to enter basic salary and calculate gross salary and net salary depending on following terms:DA=10% of basic,HRA=20% of basic,TA=15% of basic,PF=200 Rs.

//Calculate gross salary and net salary

import java.util.Scanner;

public class Salary {

public static void main(String args[])
{
long bs;
                int pf=200;
                float gs,hra,ta,da,net;


                Scanner sc=new Scanner(System.in);
        System.out.println("Enter basic salary:");
        bs=sc.nextLong();

                hra=(0.2f)*bs;
        ta=(0.15f)*bs;
        da=(0.1f)*bs;

        gs=bs+da+hra+ta;
        net=gs-pf;

        System.out.println("Basic Salary:"+bs);
        System.out.println("HRA:"+hra);
        System.out.println("DA:"+da);
        System.out.println("TA:"+ta);
        System.out.println("PF:"+pf);
        System.out.println("Gross Salary:"+gs);
        System.out.println("Net Salary:"+net);



}
}

WAP in java to accept two nos m & n and to display all nos between m and n.

//Accept m and n and display nos between given range

import java.util.Scanner;

class Range {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter values of m and n:");
int m=sc.nextInt();
int n=sc.nextInt();

if(m==n)
System.out.println("No nos.");
else if(m>n)
{
for(int i=m;i<=n;i++)
System.out.println(i);
}
else
{
for(int i=n;i<=m;i++)
System.out.println(i);
}
}

}