IQ

Ad SpeedyAds

Wednesday, October 3, 2012

Java porgram to check whether a number is Armstrong number

//program for checking Armstrong Number
//An Armstromg number is one which is equal to the sum of the cubes of its digits
//Eg. 153=1³+5³+3³=1+125+27=153...
import java.io.*;
class armstrong
{
 public static void main(String aa[]) throws IOException
{
 BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
int a, b=0, c, d;
System.out.println("Enter a number to check for Armstong");
String S=br.readLine();
a=Integer.parseInt(S);
c=a;
while(c!=0)
{
 d=c%10;
 c=c/10;
 b+=d*d*d;
}
if(a==b)
System.out.println(a+" is an Armstrong no.");
else
System.out.println(a+" is NOT an Armstrong no.");
}
}

Friday, March 9, 2012

Java program to print the words of a sentence in reverse

import java.io.*;
class abc
{
public static void main(Stringa aa[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a sentence");
String S=br.readLine();
S=S.trim();
S=" "+S+" ";
int L=S.length(),a=L;
for(int i=L-1; i>=0; i--)
{
if(S.charAt(i)==32)
{
System.out.print(S.substring(i+1,b)+" ");
b=i;
}
}
}
}