-1

i wonder, how many characters can i print using standard output in java on windows Like this:

for(int i = 0; i < Integer.MAX_VALUE; i++){
   System.out.println((char)i);
}

What ascii table using standard output?

staigoun
  • 75
  • 1
  • 7
  • Java's default `file.encoding` on Windows is `Cp1252` but you can change it. That encoding supports the ASCII chars (0-0x7F), slightly less than 32 Windows-chosen characters mostly in the U+20xx block, and the "G1" part of ISO-8859-1 aka Latin-1 (0xA0-0xFF). Other 8-bit encodings will provide 256 or slightly less characters but different ones. Unicode encodings will provide the nearly 65536 "UCS-2" or "BMP" chars, and optionally more; the UTF-8 and UTF-16{,BE,LE}[BOM] encodings are supported by many/most other software on Windows but not all; UTF-8 is supported by many other systems. – dave_thompson_085 Dec 30 '14 at 13:32

3 Answers3

0

Since a String is a char-array you should be limited by the Integer.MAX_VALUE(2147483647). Although most of the IDE's have a custom limit for the console output.

dehlen
  • 7,325
  • 4
  • 43
  • 71
  • Java `char` is 16 bits unsigned and limited to 65535, and the values are the characters in the Unicode "Basic Multilingual Plane" (BMP). Some additional (but rare) *characters* are represented by *two* `char`s, called a "surrogate pair". Casting `int` to `char` takes the low 16 bits, so that loop repeats all `chars` a hair less than 32768 times. – dave_thompson_085 Dec 30 '14 at 13:33
0

Try this. You can go upto 255. After 255 all you can see for (char)i is ?

public class Testing{
    public static void main(String args[]){
        for(int i = 0; i < Integer.MAX_VALUE; i++){
            System.out.println(i+" "+(char)i);
            if(i == 270){
                break;
            }
        }
    }
}
Abhay Pai
  • 314
  • 4
  • 17
0

your code does not concatenate or accumulate output so it will print 1 char at a time so it will print 2^31-1 (2 to the power 31) - 1 character each in a separate line

though, some characters will appear as rubbish character or a white space, this is due to the charset being used, and supported by the IDE/terminal view used to display the output.

more on Integer.MAX_VALUE

Yazan
  • 6,074
  • 1
  • 19
  • 33