Magic numbers are those numbers
where sum of the digits when converted into a single digit becomes 1.
Examples of some of the magic
numbers are 100, 37, 55, 127
100 while converted in to single digit becomes 1+0+0=1
37 while converted in to single digit becomes 3+7 = 10 = 1+0=1
import java.io.*;
class Max
{
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
int a;
int sum;
public void show()throws
Exception
{
System.out.println("Enter
the number:");
a=Integer.parseInt(br.readLine());
while(true)
{
sum=0;
if(a<10)
break;
while(a>0)
{
sum=sum+a%10;
a=a/10;
}
a=sum;
sum=0;
}
if(a==1)
System.out.println("The
number is a magic number.");
else
System.out.println("The
number is not a magic number.");
}
public static void main(String
args[])throws Exception
{
Max ob=new Max();
ob.show();
}
}
Sample output:
Enter the number:
127
The number is a magic number.
Enter the number:
34
The number is not a magic number.
hello sir!
ReplyDeletesir can you please give some expected programs(solved) for the isc 2012 practical. practical is on 24-02-2012.
I have already posted expected programs in ISC 2012, please search.
Deletehow to convert a character to its ascii code??
ReplyDeleteclass Pattern
Delete{
void show(char ch)
{
int i;
i=(int)ch;
System.out.println("Character="+ch + " and the ascii value value="+i);
}
}
thanx a lot 4 posting these programs!
ReplyDeleteCan u please post some pgms important for icse 2014 please sir it's a request
ReplyDeletePlease go through: http://schooljava.blogspot.com/2014/02/last-minute-suggestion-for-icse-2014.html
Delete