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


}

WAP in java to accept 2 nos and display minimum and maximum between them.

//Minimum and maximum between 2 nos

import java.util.Scanner;


class Min_Max {

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

if(a==b)
System.out.println("Both are equal.");
else if(a>b)
System.out.println("Max="+a+" Min="+b);
else
System.out.println("Max="+b+" Min="+a);
}
}

WAP in java to accept 3 nos and display minimum between them.

//Min between 3 nos

import java.util.Scanner;

public class Min_3 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 3 nos:");
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();

if((a==b)&&(b==c))
System.out.println("All 3 are equal.");
else if(a<b && (a<c || b==c))
System.out.println("Min="+a);
else if(b<c && (b<a || a==c))
System.out.println("Min="+b);
else
System.out.println("Min="+c);
}

}

WAP in java to accept 3 nos from user and display maximum between them.

//Max between 3 nos.

import java.util.Scanner;

class Max_3 {

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

if((a==b)&&(b==c))
System.out.println("All 3 are equal.");
else if(a>b && (a>c || b==c))
System.out.println("Max="+a);
else if(b>c && (b>a || a==c))
System.out.println("Max="+b);
else
System.out.println("Max="+c);
}
}

WAP in java to check whether the entered character is in upper case or small case.

//Check case of letter

import java.util.Scanner;

class Letter {

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

if(x>='A' && x<='Z')
System.out.println("Uppercase Letter");
else if(x>='a' && x<='z')
System.out.println("Lowercase Letter");
else
System.out.println("It's not a letter.");
}

}

WAP in java to check whether the entered year is leap year or not using conditional operators.

//Check Leap year using conditional operators

import java.util.Scanner;

class Leap_year {

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

String result=((yr%100==0 && yr%400==0)||(yr%100!=0 && yr%4==0))?"a Leap Year.":"not a Leap year";

System.out.println("It is "+result);
}
}

WAP in java to display Fibonacci series up to the limit entered by user.

//Display Fibonacci series up to given limit

import java.util.Scanner;

public class Fibonacci {

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

System.out.println("Enter a limit for fibonacci series:");
l=sc.nextInt();

if(l<=0)
System.out.println("Invalid input");
else
{
int a=0,b=1,c;

System.out.println("Fibonacci Series for limit "+l);
System.out.println(a);
System.out.println(b);

while(l>0)
{
c=a+b;
System.out.println(c);
a=b;
b=c;
l--;
}
}
}

}

WAP in java to calculate factorial of a given no.

//Calculate Factorial of a given no

import java.util.Scanner;

public class Factorial {

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 if(no==0)
System.out.println("Factorial=1");
else
{
long f=1L;

for(int i=1;i<=no;i++)
f=f*i;

System.out.println("Factorial="+f);
}
}

}

WAP in java to check whether the entered no is even or odd.

//Check no is even or odd

import java.util.Scanner;

class Even_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%2==0)
System.out.println("Even no");
else
System.out.println("Odd no");
}

}

WAP in java to accept employee no and basic salary,and to calculate gross salary depending upon following conditions:1)If basic salary>5000 then HRA=5%,DA=8%,TA=500 2)If basic salary>2000 then HRA=4%,DA=6%,TA=300 otherwise HRA,DA,TA are not given.

//Employee no and salary calculations
import java.util.Scanner;

class Employee {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter employee no and basic salary:");
int eid=sc.nextInt();
float bs=sc.nextFloat();

float hra,da,ta,gs;

if(bs>5000)
{
hra=0.05f*bs;
da=0.08f*bs;
ta=500;
}
else if(bs>2000)
{
hra=0.04f*bs;
da=0.06f*bs;
ta=300;
}
else
hra=da=ta=0;

gs=bs+hra+da+ta;
System.out.println("Employee no:"+eid+" Gross Salary:"+gs);

}

}

The distance between 2 cities (in km) is input through the keyboard.WAP in java to convert and print the distance in meters,feets,inches and centimeters.

//Conversion of distance

import java.util.Scanner;

class Distance {

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

System.out.println("Enter distance between two cities in km:");
int d=sc.nextInt();

System.out.println("Distance in meters:"+(d*1000));
System.out.println("Distance in centimeters:"+(d*100000));
System.out.println("Distance in feets:"+(d*3280.84f));
System.out.println("Distance in inches:"+(d*39370.1f));

}
}

A cashier has currency notes of denominations 10,50 and 100.If the amount to be withdrawn is the input through the keyboard in hundreads,WAP in java to find the total no of currency notes of each denomination the cashier will have to give to the withdrawer.

//Currency Denominations of 100,50 and 10

import java.util.Scanner;

class Currency {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter amount which can be denominated in 10:");
long a=sc.nextLong();

if(a<0 || a%10!=0)
System.out.println("Invalid Input");
else
{
System.out.println("Denominations of 100:"+(a/100));
a=a%100;
System.out.println("Denominations of 50:"+(a/50));
a=a%50;
System.out.println("Denominations of 10:"+(a/10));
}
}
}

WAP in java to display class of Student based on marks. 1)Distinction for 70 and above 2)First class for 60 and above 3)Second class for 50 and above 4)Third class for 40 and above 5)Fail for below 40

//Class depending on marks

import java.util.Scanner;

class Class {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter marks of a student:");
int m=sc.nextInt();

if(m>=70)
System.out.println("Distinction");
else if(m>=60)
System.out.println("First Class");
else if(m>=50)
System.out.println("Second Class");
else if(m>=40)
System.out.println("Third Class");
else
System.out.println("Fail");

}

}

WAP in java to accept an age of an employee and calculate Bonus based on following:If age >25 then bonus is 5000,otherwise 3000.

//Bonus program using conditional operator

import java.util.Scanner;

class Bonus {

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

b=(age>25)?5000:3000;
System.out.println("Your Bonus:"+b);
}

}

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

//Armstrong no

import java.util.Scanner;

public class Armstrong {

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,d,n=no;
while(no>0)
{
d=no%10;
s=s+(d*d*d);
no=no/10;
}

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

}

WAP in java to display Absolute value of a given no using conditional operator

//Absolute value using conditional operator

import java.util.Scanner;

class Absolute {

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

int a=(no<0)?no*(-1):no;

System.out.println("Absolute value:"+a);
}

}

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

//Prime no:

import java.util.Scanner;

public class Prime {

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

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

if(no<1)
System.out.println("Can not determine");
else if(no==2)
System.out.println("It is a prime no.");
else
{
int p=1;

for(int i=2;i<no;i++)
{
if(no%i==0)
{
p=0;break;
}
}
if(p==1)
System.out.println("It is a prime no.");
else
System.out.println("It is not a prime no.");
}

}

}

WAP in java using switch case for following: Area of a circle Area of a square Area of a right angled triangle Area of a rectangle Circumference of a circle Perimeter of a square Accept inputs like radius,side,etc through keyboard.

//Menu driven program using switch case:

import java.util.Scanner;
class Geometry



{
         public static void main(String args[])
          {
                Scanner s=new Scanner(System.in);
                
                System.out.println("MENU:");
                System.out.println("1.Area of a Circle");
System.out.println("2.Area of a Square");
System.out.println("3.Area of a Right Angled Triangle");
System.out.println("4.Area of a Rectangle");
System.out.println("5.Circumference of a Circle");
System.out.println("6.Perimeter of a Square");
System.out.println("7.Exit");
                System.out.println("Enter your option:");
                int op=s.nextInt();

                switch(op)
                {
                      case 1: System.out.println("Enter radius:");
                                  float r=s.nextFloat();
                                  float ac=3.14f*r*r;
                                 System.out.println("Area:"+ac);
                                 break;

                     case 2: System.out.println("Enter side:");
                                  int x=s.nextInt();
                                  int as=x*x;
                                 System.out.println("Area:"+as);
                                 break;

                     case 3: System.out.println("Enter height and base:");
                                  float h=s.nextFloat();
                                  float bs=s.nextFloat();
                                  float art=0.5f*h*bs;
                                 System.out.println("Area:"+art);
                                 break;

                    case 4: System.out.println("Enter length and breadth:");
                                  int l=s.nextInt();
                                  int b=s.nextInt();
                                  int ar=l*b;
                                 System.out.println("Area:"+ar);
                                 break;

                   case 5: System.out.println("Enter radius:");
                                  float R=s.nextFloat();
                                  float C=3.14f*2f*R;
                                 System.out.println("Circumference:"+c);
                                 break;


                    case 6: System.out.println("Enter side:");
                                  int X=s.nextInt();
                                  int p=4*X;
                                 System.out.println("Perimeter:"+p);
                                 break;

                     default:System.out.exit(0);
                    }
                 }
}