This may sound very easy or an old stupid question, but it is quite different for me. I have written a Program for a half-Descending pyramid Pattern which is like this.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
I know this is very easy, the trick is I don't wanna do this by use of Scanner
and Integer.parseInt()
. I am trying to do this with BufferedReader
and InputStreamReader
.
So when I execute the following code of my main method with a input of 5 in num. It reads it as 53 when I print it. I have no idea why it's happening. But when I use the 'Integer.parseInt(br.readLine())' method it gives the exact output. How is it supposed to happen when read method is supposed to read int values. Please clear it.
int num1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter hte value of num1");
//num1=Integer.parseInt(br.readLine());
num1=br.read();
System.out.println(num1);
for(int i=0;i<num1;i++)
{
for(int j=0;j<=i;j++)
{
System.out.print(j+"\t");
}
System.out.println();
}
It's my first question so please ignore the silly mistakes, I have tried to write it as best as I could. Thanks..