Simple program from DEITLE’s book , read 5 integers and the program should print line containing that number of adjacent asterisks .i.e (if num = 5 the output *****) .
I have tested the same solution in c++ and it worked fine . yet, here the buffer is holding strange values (50 ?) .
I think the problem is in using the buffer , however i want to know why this is happening?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.io.*;
import java.util.Date;
/**
* Program that reads five numbers and print starts equal to each number
*
* @author Hassan
*/
public class JavaApplication1
{
public static void main(String[] args)
{
int num ;
java.io.InputStreamReader ins= new InputStreamReader(System.in);
java.io.BufferedReader bfr = new BufferedReader (ins);
try
{
for(int i=0;i<5;i++)
{
System.out.println("Please Enter a number");
num = bfr.read();
System.out.print(num);
for(int j=0;j<num;j++)
{ System.out.print("* "); }
System.out.println("\n");
}
}
catch(Exception E )
{System.out.println(E.getMessage()); }
}
}
EDIT :the problem has been solved , yet the program -out of 5 inputs -is reading 3 only i.e its reading input and ignoring the next one

You’re reading a byte, which will just be the ascii value of the first available character. 50 is ‘2’ in ascii. You probably want to read, and parse, a number entered as text.
If you use
readLine()instead ofread(), into aString, you can then useInteger.parseInt()to get the real value.