Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Lesson 7 Coding Activity Question 2
- *
- * Change the last problem so that it also prints the sum of the digits.
- * Use the format shown below.
- *
- * Make sure your output is printed in the same order as the sample run.
- *
- * Sample run:
- Please enter a three digit number:
- 678
- Here are the digits:
- 6
- 7
- 8
- 6 + 7 + 8 = 21
- */
- import java.util.Scanner;
- import java.lang.Math;
- import java.io.*;
- class Lesson_7_Activity_Two {
- public static void main(String[] args) throws IOException {
- System.out.println("Please enter a three digit number:");
- Scanner scan= new Scanner(System.in);
- int x = scan.nextInt();
- int y = x/100;
- int z = (int)(x*.1)%10;
- int a = x%10;
- System.out.println("Here are the digits:\n" + y + "\n" + z + "\n" + a + "\n" + y + " + " + z + "+ " + a + "= " + (y + z + a));
- }
- }
Add Comment
Please, Sign In to add comment