Upload
arnold
View
91
Download
0
Embed Size (px)
DESCRIPTION
/** * File: DigitSum.java */ public void run() { int number = readInt("Enter a number greater than 0: "); if (number
Citation preview
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
0 digitSum
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
0 digitSum
1729 n
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
0 digitSum
1729 n
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
0 digitSum
1729 n
9 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
9 digitSum
1729 n
9 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
9 digitSum
172 n
9 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
9 digitSum
172 n
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
9 digitSum
172 n
2 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
11 digitSum
172 n
2 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
11 digitSum
17 n
2 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
11 digitSum
17 n
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
11 digitSum
17 n
7 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
18 digitSum
17 n
7 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
18 digitSum
1 n
7 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
18 digitSum
1 n
7 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
18 digitSum
1 n
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
18 digitSum
1 n
1 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
19 digitSum
1 n
1 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
19 digitSum
0 n
1 digit
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
19 digitSum
0 n
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
19 digitSum
0 n
/** * File: DigitSum.java */
public void run() { int number = readInt("Enter a number greater than 0: "); if (number <= 0) { println("Your response should have been positive."); println("You're no fun to play number games with."); return; // end prematurely without continuing }
int digitSum = 0; int n = number; while (n > 0) { int digit = n % 10; digitSum += digit; n /= 10; }
println("The sum of the digits making up " + number + " is " + digitSum + "."); println("Thanks for playing. :)");}
1729 number
19 digitSum
0 n