0

I haven an assignment for school and I'm a beginner into Java. I did the ASCII char loops like I needed to, but I want it to look pretty.

How do I make a single for-loop into multiple columns to show up on the output screen without having to scroll?

public static void main(String[] args) {
   for (int i = 32; i <= 126; i++) 
       System.out.println((char) i);
}//end main
3
  • Please explain more what you're trying to do. ASCII char loops? Is this trying to print out a table of the printable ASCII character set? Commented Aug 30, 2013 at 18:23
  • @chrylis Yes kind of like a table, but I just need 3 columns to make it look pretty. I can add lines and such myself. I just can't figure out how to make it split into 3 or 4 columns. Commented Aug 30, 2013 at 18:29
  • See my answer, and just adjust my 8 columns to whatever you think looks good. Commented Aug 30, 2013 at 18:30

1 Answer 1

1

Instead of using System.out.println, just use System.out.print, and on each iteration through the loop, check to see whether i % 8 == 7 (or the equivalent for some other line length). If it is, print a newline; otherwise, print a tab or some spaces.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.