Created
March 17, 2011 12:52
-
-
Save pdeaudney/874265 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Write a Java program that reads one 6-digit integer from the user. | |
| * It then prints out these 6 digits, each separated from the preceding one by 2 spaces. | |
| */ | |
| import java.util.*; | |
| public class Week2Exercise6{ | |
| public static void main(String[] args){ | |
| System.out.println("Please enter in a single six digit integer:"); | |
| Scanner i = new Scanner(System.in); | |
| int thesixdigits = 0; | |
| thesixdigits = i.nextInt(); | |
| String convertedInt = ""; | |
| convertedInt = Integer.toString(thesixdigits); | |
| int length = convertedInt.length(); | |
| StringBuffer finalout = new StringBuffer(); | |
| for (int z = 0; z < convertedInt.length(); z++){ | |
| finalout.append(convertedInt.charAt(z) + " "); | |
| } | |
| String finalfinalout = ""; | |
| finalfinalout = finalout.toString(); | |
| //System.out.println("Printing not so final output: " + finalout + "."); | |
| System.out.println("Printing output: " + finalfinalout.trim() + "."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment