26
/** * 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() {

  • 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

Page 1: ** * File: DigitSum.java */ public  void run() {

/** * 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. :)");}

Page 2: ** * File: DigitSum.java */ public  void run() {

/** * 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. :)");}

Page 3: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 4: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 5: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 6: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 7: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 8: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 9: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 10: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 11: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 12: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 13: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 14: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 15: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 16: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 17: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 18: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 19: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 20: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 21: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 22: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 23: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 24: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 25: ** * File: DigitSum.java */ public  void run() {

/** * 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

Page 26: ** * File: DigitSum.java */ public  void run() {

/** * 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