Advertisement
StefanTobler

Lesson 7 Activity 1

Sep 12th, 2016
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. /*
  2.  * Lesson 7 Coding Activity Question 1
  3.  *
  4.  * Input a positive three digit integer. Print out the digits one per line.
  5.  *
  6.  * Sample run:
  7.  
  8. Please enter a three digit number:
  9. 678
  10.  
  11. Here are the digits:
  12. 6
  13. 7
  14. 8
  15.  
  16. */
  17.  
  18. import java.util.Scanner;
  19. import java.lang.Math;
  20. import java.io.*;
  21.  
  22.  
  23. class Lesson_7_Activity_One {
  24.     public static void main(String[] args) throws IOException {
  25.       System.out.println("Please enter a three digit number:");
  26.       Scanner scan= new Scanner(System.in);
  27.       int x = scan.nextInt();
  28.       int y = x/100;
  29.       int z = (int)(x*.1)%10;
  30.       int a = x%10;
  31.      
  32.  
  33.       System.out.println("Here are the digits:\n" + y + "\n" + z + "\n" + a + "\n" + y + " + " + z + "+ " + a + "= " + (y + z + a));
  34.  
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement