StefanTobler

Lesson 7 Activity 2

Sep 12th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. /*
  2.  * Lesson 7 Coding Activity Question 2
  3.  *
  4.  * Change the last problem so that it also prints the sum of the digits.
  5.  * Use the format shown below.
  6.  *
  7.  * Make sure your output is printed in the same order as the sample run.
  8.  *
  9.  * Sample run:
  10.  
  11. Please enter a three digit number:
  12. 678
  13.  
  14. Here are the digits:
  15. 6
  16. 7
  17. 8
  18.  
  19. 6 + 7 + 8 = 21
  20.  
  21. */
  22. import java.util.Scanner;
  23. import java.lang.Math;
  24. import java.io.*;
  25.  
  26.  
  27. class Lesson_7_Activity_Two {
  28.     public static void main(String[] args) throws IOException {
  29.       System.out.println("Please enter a three digit number:");
  30.       Scanner scan= new Scanner(System.in);
  31.       int x = scan.nextInt();
  32.       int y = x/100;
  33.       int z = (int)(x*.1)%10;
  34.       int a = x%10;
  35.      
  36.  
  37.       System.out.println("Here are the digits:\n" + y + "\n" + z + "\n" + a + "\n" + y + " + " + z + "+ " + a + "= " + (y + z + a));
  38.  
  39.  
  40.     }
  41. }
Add Comment
Please, Sign In to add comment