Skip to content

Instantly share code, notes, and snippets.

@pdeaudney
Created March 17, 2011 12:52
Show Gist options
  • Select an option

  • Save pdeaudney/874265 to your computer and use it in GitHub Desktop.

Select an option

Save pdeaudney/874265 to your computer and use it in GitHub Desktop.
/*
* 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