1 / 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.");

arnold
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

  5. /** * 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. :)"); } number 1729 digitSum 0

  6. /** * 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. :)"); } number 1729 digitSum 0 n 1729

  7. /** * 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. :)"); } number 1729 digitSum 0 n 1729

  8. /** * 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. :)"); } number 1729 digitSum 0 n 1729 9 digit

  9. /** * 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. :)"); } number 1729 digitSum 9 n 1729 9 digit

  10. /** * 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. :)"); } number 1729 digitSum 9 n 172 9 digit

  11. /** * 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. :)"); } number 1729 digitSum 9 n 172

  12. /** * 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. :)"); } number 1729 digitSum 9 n 172 2 digit

  13. /** * 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. :)"); } number 1729 digitSum 11 n 172 2 digit

  14. /** * 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. :)"); } number 1729 digitSum 11 n 17 2 digit

  15. /** * 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. :)"); } number 1729 digitSum 11 n 17

  16. /** * 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. :)"); } number 1729 digitSum 11 n 17 7 digit

  17. /** * 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. :)"); } number 1729 digitSum 18 n 17 7 digit

  18. /** * 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. :)"); } number 1729 digitSum 18 n 1 7 digit

  19. /** * 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. :)"); } number 1729 digitSum 18 n 1 7 digit

  20. /** * 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. :)"); } number 1729 digitSum 18 n 1

  21. /** * 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. :)"); } number 1729 digitSum 18 n 1 1 digit

  22. /** * 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. :)"); } number 1729 digitSum 19 n 1 1 digit

  23. /** * 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. :)"); } number 1729 digitSum 19 n 0 1 digit

  24. /** * 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. :)"); } number 1729 digitSum 19 n 0

  25. /** * 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. :)"); } number 1729 digitSum 19 n 0

  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. :)"); } number 1729 digitSum 19 n 0

More Related