Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9093407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:05:35+00:00 2026-06-16T23:05:35+00:00

I am trying out a simple program for printing characters. When I do this:

  • 0

I am trying out a simple program for printing characters. When I do this:

import java.io.*;

public class listit {

  public static void main(String[] args) {

    for (int i = 32; i < 127; i++) {
      System.out.write(i);
      // break line after every eight characters.
      if (i % 8 == 7) System.out.write('\n');
      else System.out.write('\t');
    }
    System.out.write('\n');
   }
} 

I am getting the expected result, that is, the printable subset of the ASCII character set is being printed out. However, when I try something similar:

import java.io.*;
public class listit {
public static void main(String[] args) {
int i = 122;
System.out.write(i);
}
}

I am getting no output at all, while I was expecting z. How is this program different from the one above, save the absence of a loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:05:36+00:00Added an answer on June 16, 2026 at 11:05 pm

    PrintStream supports auto-flushing or flushing on a newline.

    System.out has auto-flushing enabled but for System.out.write(‘A’) it will only auto-flush if you write a newline. Note: if you do System.out.write(“A”.getByte()) will auto-flush.

    The Javadoc for PrintStream.write(int) states

    Writes the specified byte to this stream. If the byte is a newline and
    automatic flushing is enabled then the flush method will be
    invoked.

    This means you need auto-flush AND write a newline.

    Note: PrintStream.print(char) states

    these bytes are written in exactly the manner of the write(int) method.

    This doesn’t make it clear that the flushing is different.
    It will flush if you have auto-flush OR write a new line.

    System.out.print('a');
    System.out.write('b');
    

    prints just

    a
    

    I suspect this inconsistency is a long standing bug rather than a feature (in other words it won’t be fixed). 😉

    This means you have to either

    System.out.flush();
    

    or

    System.out.write('\n');
    

    to see the last line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.util.Scanner; public class Assignment1Q3 { public static void main(String[] args) { Scanner in
I was trying out the Java ForkJoin framework and wrote a simple test program
I'm trying out a very simple Java program that uses Scanner and its method
I'm trying to abstract out a method from a simple program. This method tests
I'm trying to write a very simple program, I want to print out the
i just started learning swings. And thought of trying out a simple program, but
I am trying out a very simple cpp program on osx just to get
I am trying to write a simple program for this interview question: Write a
i am trying to get this very simple program working . program runs it
Basically, Im just trying out a very simple collision test for another program Im

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.