java - Input stream reader- read method return wrong value -


This can be a very simple or old silly question, but it is completely different for me, I have a semi-descending pyramid pattern Has written a program that is in this way.

1 2

1 2 3

1 2 3

1 2 3> 1 2 3 4

1 2 3 4 5

I know it is very easy, I do not want to do it using the scanner / code> and integer.parseant () . I'm trying to do this with BufferedReader and InputStreamReader . So when I execute the following code of my main method then there is input in 5 digits. It reads it as 53 when I print it. I do not know why this is happening. But when I got 'Integer. It uses precision ('breadline ())' method, so it gives accurate output. It should be done when reading the int value in the way of reading. Please clear it.

  int num1; Buffettder br = new buffed reader (new input striker reader (system.)); System.out.println ("insert the html value of num1"); //num1=Integer.parseInt (br.readLine ()); Number 1 = br.read (); Println (number1); For (int i = 0; i & lt; num1; i ++) {for (int j = 0; j & lt; = i; j ++) {System.out.print (j + "\ t" ); } System.out.println (); }   

This is my first question so please ignore mistakes of mistakes, I have tried to write it as much as possible. Thanks ..

This reads it as 53 when I print it.

Yes, it will be. Because you are calling reading () , which gives the same letter, or 1 to indicate at the end of the data

Unicode value is 5 in character '5', so what you are looking for (your variable is a int , after all.) If you type num1 to char , you will see '5'.

When you want to change the literal representation of an integer in an integer value , you usually Integer.parseInt .

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -