I am a newbie to Java, and as an exercise wanted to WAP a simple program to print required no. of \'*\' characters according to the user. But somehow, the output of this cod
There are two mistakes in your code.
First
System.in.read()
Is reading a byte, not a integer, so, it is parsing the integer and getting the first byte of it.
Second
for (i = 0; i <= n; i++) {
will print always one star more than requested. So, it should be changed to
for (i = 0; i < n; i++) {
Suggestion: You could use Scanner to read your integer, for example
Scanner scanner = new Scanner(System.in);
no_stars = scanner.nextInt();