First off, indent you code properly: pick a style and be consistent - it makes your code more readable:
import java.util.*;
class b1 {
public static void main() {
Scanner sc = new Scanner(System.in);
int sum = 0;
System.out.print("Enter a Number");
int n = sc.nextInt();
do {
int c = n % 10;
int s = c * c;
sum = sum + s;
n = n / 10;
}
while (sum == 1); {
if (sum == 1)
System.out.print("It is a Happy Number");
else
System.out.print("It is not a Happy Number");
}
}
}
Then look at your instructions - they tell you what to do:
1) To find out if a number is a MAGIC number or not add its digits.
2) Now add the digits of the sum obtained.
3) Repeat this process from (2) until you get a single digit number.
4) If you get 1 in the end the given number is a MAGIC number
5) It would appear this should be a method rather than direct in main.
Your code doesn't do that: It exit the loop as soon as the sum isn't one, regardless of the number of digits entered. So if I enter "11111111111112" it will process one single digit: "2" and exit the do loop. Think about how you detect you are out of digits ... it's pretty obvious!
I'd start by writing a "helper method" to take an integer parameter, and return the sum of it's digits.
Then call that in a loop until you have a single digit remaining.
Always sit down and think before you leap into code: it will save you a huge amount of wasted time. This may help you:
How to Write Code to Solve a Problem, A Beginner's Guide[
^]