Tuesday, 28 July 2015

Find the third max from input four number

import java.io.*;
class Max
{
public static void main(String args[])
{
int a,b,c,d,max1=0,max2=0,max3=0,max4=0;
Console con = System.console();
System.out.print("enter value of a");
a=Integer.parseInt(con.readLine());
System.out.print("enter value of b");
b=Integer.parseInt(con.readLine());
System.out.print("enter value of c");
c=Integer.parseInt(con.readLine());
System.out.print("enter value of d");
d=Integer.parseInt(con.readLine());
if(a>b)
{
max1=a;
max2=b;
}
else
{ max1=b;
max2=a;
}
if(c>max1)
{
max3=max2;
max2=max1;
max1=c;
}
else if(c>max2)
{
max3=max2;
max2=c;
}
else
max3=c;
if(d>max1)
{
max4=max3;
max3=max2;
max2=max1;
max1=d;
}
else if(d>max2)
{
max4=max3;
max3=max2;
max2=d;
}
else if(d>max3)
{
max4=max3;
max3=d;
}
else
max4=d;
System.out.println("max1 ="+max1+"\n max2 ="+max2+"\n max3 ="+max3+"\n max4 ="+max4);
}
}

Thursday, 16 July 2015

How to find Palidrom

import java.io.*;
class pallidrom
{
public static void main(String args[])
{
int a,b,n,sum=0;
Console con = System.console();
n = Integer.parseInt(con.readLine());
b=n;
while(n!=0)
{
a=n%10;
sum = sum*10+a;
n=n/10;
}
if(b== sum)
System.out.print(b+"Number is pallidrom");
else
System.out.print(sum+"Number is not pallidrom");
}
}

Saturday, 4 July 2015

Write a Program for Series

 1=1
 12=1+2=3
 36=3+6=9
 123456789=1+2+3+4+5+6+7+8+9=45

import java.io.*;
class Example
{
public static void main(String args[])
{
int a,n,sum=0;
Console con = System.console();
n = Integer.parseInt(con.readLine());
while(n!=0)
{
a=n%10;
sum = sum+a;
n=n/10;
}
System.out.print(n+" series add is"+sum);
}
}