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

}

WAP in java to accept n from user and to display all odd nos from 1 up to n.

//Odd nos. from 1 up to given range

import java.util.Scanner;

class Range_odd {

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

if(n<1)
System.out.println("INVALID INPUT");
else
{
for(int i=1;i<=n;i=+2)
System.out.println(i);
}
}

}

WAP in java to accept n from user and to display all even and odd nos from 1 up to n.

//Even and odd nos. from 1 up to given range

import java.util.Scanner;

class Range_evn_odd {

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

if(n<1)
System.out.println("INVALID INPUT");
else
{
System.out.println("Even Nos:");
for(int i=2;i<=n;i=+2)
System.out.println(i);

System.out.println("Odd Nos:");
for(int i=1;i<=n;i=+2)
System.out.println(i);


}
}

}

WAP in java to accept n from user and display all even nos from 1 up to n.

//Even nos. from 1 up to given range

import java.util.Scanner;

class Range_even {

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

if(n<1)
System.out.println("INVALID INPUT");
else
{
for(int i=2;i<=n;i=+2)
System.out.println(i);
}
}

}

WAP in java to accept cost price and selling price of an item and determine whether the profit or loss will be there and also determine how much profit or loss incurred.

//Determine whether(and how much) profit or loss is incurred

import java.util.Scanner;

class ProfitOrLoss {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Selling Price and Cost Price(respectively):");
float sp=sc.nextFloat();
float cp=sc.nextFloat();

if(sp==cp)
System.out.println("Neither profit nor loss");
else if(sp>cp)
System.out.println("Profit="+(sp-cp));
else
System.out.println("Loss="+(cp-sp));
}


}

If the total selling price of 15 items and the total profit earned on item is input through the keyboard,WAP in java to find cost price of one item.

//Calculate cost price of a product

import java.util.Scanner;


public class Product_cp {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Selling price for 15 items(in total) and enter profit per item:");
float sp_t=sc.nextFloat();
float p=sc.nextFloat();

float cp=(sp_t/15)-p;
System.out.println("Cost price per item:"+cp);
}

}

WAP in java to convert positive no into negative no and vice versa.

//Interchange sign of a no

import java.util.Scanner;


class Pos_Neg {

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

System.out.println("New No:"+(n*(-1)));
}


}

In a town,the percentage of men is 52.The percentage of total literacy is 48.If total percentage of literate men is 35 of the total populations,WAP in java to find the total no of illiterate men and women ,if the population of the town is 80000.

//Population=80000,Men=52% of population,Literate people=48% of population, Literate Men=35% of Population
//Program to display count of illiterate men and illiterate women

class Population {

public static void main(String args[])
{
long pop=80000,ilm,ilw;

ilm=(long)((0.52*pop)-(0.35*pop)); //Illiterate men
ilw=(long)((0.52*pop)-ilm); //Illiterate women

System.out.println("Population:"+pop);
System.out.println("Illiterate men:"+ilm);
System.out.println("Illiterate women:"+ilw);
}

}

WAP in java to check whether the entered no is perfect or not.

//To check no is perfect or not

import java.util.Scanner;

public class Perfect {

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

System.out.println("Enter a no:");
int no=sc.nextInt();

if (no%2!=0)
System.out.println("It is not a perfect no.");
else
{
int n=0;

for(int i=1;i<no;i++)
{
if(no%i==0)
n=n+i;
}

if(n==no)
System.out.println("It is a perfect no.");
else
System.out.println("It is not a perfect no.");
}


}

}

WAP in java to print following star pattern.

/* PATTERN IS-  *****
                              ****
                              ***
                              **
                              *                                      */


class Pattern_2 {

public static void main(String args[])
{
for(int i=5;i>0;i--)
{
for(int j=1;j<=i;j++)
System.out.print("*");
System.out.println();
}
}

}

WAP in java to print following pattern of stars.

/*   PATTERN IS-  *
                                **
                                ***
                                ****
                                *****                              */



class Pattern_1 {

public static void main(String args[])
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
System.out.print("*");
System.out.println();
}
}

}

WAP in java to check whether the entered no is Palindrome or not.

//To check no is palindrome or not
import java.util.Scanner;

public class Palindrome {

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

System.out.println("Enter a no:");
int no=sc.nextInt();

if(no<=0)
System.out.println("Can not determine");
else
{
int s=0,n=no;

while(no>0)
{
s=(s*10)+(no%10);
no=no/10;
}

if(n==s)
System.out.println("It is a Palindrome no.");
else
System.out.println("It is not a Palindrome no.");
}
}

}

WAP in java to calculate overtime pay of 10 employees.Overtime is paid at the rate of 12 Rs./hr for every hour worked above 40 hours.Assume that the employees do not work for the fractional part of an hour.

//Calculate overtime

import java.util.Scanner;

public class Overtime {

public static void main(String args[])
{
int e[]=new int[10],o[]=new int[10],i;
Scanner sc=new Scanner(System.in);

System.out.println("Enter overtime hrs for 10 employees:");
for(i=0;i<10;i++)
e[i]=sc.nextInt();

System.out.println("Overtime Pay for 10 employees");
{
for(i=0;i<10;i++)
{
if(e[i]>40)
o[i]=(e[i]-40)*12;
else
o[i]=0;

System.out.println("Employee No:"+(i+1)+" Overtime pay:Rs."+o[i]);
}
}

}

}

If a 5 digit no is input through the keyboard,WAP in java to print a new no by adding 1 to each of its digit.For eg. If input is 12391 then output should be 23402.

//Add 1 to each digit

import java.util.Scanner;


class No_add1 {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a 5 digit no:");
int no=sc.nextInt();

if(no<10000 || no>99999)
System.out.println("INVALID INPUT");
else
{
int a,b,c,d,e;

a=no%10;
no=no/10;

b=no%10;
no=no/10;

c=no%10;
no=no/10;

d=no%10;
no=no/10;

e=no;

if(a==9)
a=0;
else
a=a+1;


if(b==9)
b=0;
else
b=b+1;

if(c==9)
c=0;
else
c=c+1;

if(d==9)
d=0;
else
d=d+1;

if(e==9)
e=0;
else
e=e+1;

no=a+(b*10)+(c*100)+(d*1000)+(e*10000);

System.out.println("New no:"+no);
}
}


}