Sunday, 15 March 2015

Example of else if condition

import java.io.*;
class Example
{
public static void main(String args[])
{
int tax1=0;
Console con = System.console();
int a= Integer.parseInt(con.readLine());
if(a<=100000)
System.out.println("No tax");
else if(a<=200000)
{
tax1=(a-100000)*5/100;
System.out.println("Tax is"+tax1);
}
else if(a<=300000)
{
tax1=5000+(a-200000)*10/100;
System.out.println("Tax is"+tax1);
}
else if(a<=400000)
{
tax1=15000+(a-300000)*15/100;
System.out.println("Tax is"+tax1);
}
else
{
tax1=30000+(a-400000)*20/100;
System.out.println("Tax is"+tax1);
}
}
}

Thursday, 12 March 2015

Find average integer number

import java.io.*;
class pattern1
{
public static void main(String args[])
{
System.out.print(average(25,36,65,69,68,89));
}
public static int average(int...number)
{
int total=0;
for(int x:number)
total+=x;
return total/number.length;
}
}

Wednesday, 11 March 2015

Java program to find odd or even

import java.util.Scanner;

class OddOrEven
{
   public static void main(String args[])
   {
      int x;
      System.out.println("Enter an integer to check if it is odd or even ");
      Scanner in = new Scanner(System.in);
      x = in.nextInt();

      if ( x % 2 == 0 )
         System.out.println("You entered an even number.");
      else
         System.out.println("You entered an odd number.");
   }
}

Thursday, 5 March 2015

Write a Program input four number convert into like this 9999=nine thousand nine hundred ninety nine


If input 9991=nine thousand nine hundred ninety one
import java.io.*;
class program
{
public static void main(String args[])
{
int a,b,c,d,e;
Console con = System.console();
a = Integer.parseInt(con.readLine());
b = a%10;
a = a/10;
c = a%10;
a = a/10;
d = a%10;
a = a/10;
e = a%10;
switch(e)
{
case 1: System.out.print("One thousand"); break;
case 2: System.out.print("Two thousand"); break;
case 3: System.out.print("Three thousand"); break;
case 4: System.out.print("Four thousand"); break;
case 5: System.out.print("Five thousand"); break;
case 6: System.out.print("Six thousand"); break;
case 7: System.out.print("Seven thousand"); break;
case 8: System.out.print("Eight thousand"); break;
case 9: System.out.print("Nine thousand"); break;
}

switch(d)
{
case 1: System.out.print(" One hundred"); break;
case 2: System.out.print(" Two hundred"); break;
case 3: System.out.print(" Three hundred"); break;
case 4: System.out.print(" Four hundred"); break;
case 5: System.out.print(" Five hundred"); break;
case 6: System.out.print(" Six hundred"); break;
case 7: System.out.print(" Seven hundred"); break;
case 8: System.out.print(" Eight hundred"); break;
case 9: System.out.print(" Nine hundred"); break;
}
if(c==1)
{
switch(b)
{
case 0: System.out.print(" ten"); break;
case 1: System.out.print(" eleven"); break;
case 2: System.out.print(" twelve"); break;
case 3: System.out.print(" Thirteen"); break;
case 4: System.out.print(" Fourteen"); break;
case 5: System.out.print(" Fifteen"); break;
case 6: System.out.print(" Sixteen"); break;
case 7: System.out.print(" Seventeen"); break;
case 8: System.out.print(" Eighteen"); break;
case 9: System.out.print(" Nineteen"); break;
}
}
switch(c)
{
case 2: System.out.print(" Twenty"); break;
case 3: System.out.print(" Thirty"); break;
case 4: System.out.print(" Forty"); break;
case 5: System.out.print(" Fifty"); break;
case 6: System.out.print(" Sixty"); break;
case 7: System.out.print(" Seventy"); break;
case 8: System.out.print(" Eighty"); break;
case 9: System.out.print(" Ninety"); break;
}
switch(b)
{
case 1: System.out.print(" One"); break;
case 2: System.out.print(" Two"); break;
case 3: System.out.print(" Three"); break;
case 4: System.out.print(" Four"); break;
case 5: System.out.print(" Five"); break;
case 6: System.out.print(" Six"); break;
case 7: System.out.print(" Seven"); break;
case 8: System.out.print(" Eight"); break;
case 9: System.out.print(" Nine"); break;
}
}
}