import java.io.*;

class pattern
{
public static void main(String args[]) throws IOException
{
int n;
BufferedReader br = new BufferedReader(InputStreamReader(System.in()));
System.out.println("Please Enter Your Pattern Length:- ");
n = Integer.parseInt(br.readLine());

while(n>2)
{
for(int i=0;i<=n;i++)
{
if((i==1)||(i==n))
{
for(int k=0;k<=n;k++){
System.out.print("*");
System.out.println();
}
}
else
{
int o = n-2;
System.out.print("*");
for(int h=0;h<=0;h++){
System.out.print(" ");
}
System.out.print("*");
System.out.println();
}
}
}
}
}

the problem is it is pointing at (System.in()) under the . saying it cannot find symbol. But I cannot understand what is wrong with it? Please help me.

Recommended Answers

All 5 Replies

It is System.in, not System.in().

In your code there are two blunder mistakes.
1) you can not use InputStreamReader(System.in) directly as a parameter of BufferedReader class.
2) Although i have made corrections in your code but even then it is running for infinite
Here is the modified lines of code :

import java.io.*;
class pattern
{
public static void main(String args[]) throws IOException
{
int n;
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);

Or change line 8 to:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Although i have made corrections in your code but even then it is running for infinite

Yes, that happens when a value > 2 is entered for n, the while loop will keep looping as long as n > 2, and since the value of n never changes during loop execution, that will in theory be forever.

commented: Yes. ,it is more better. +0

hai all and bhadra.anurag,

check at line no 27 also

for(int h=0;h<=0;h++){

is this correct assignment value for variable 'h'?

(assigning zero and comparing with zero)

please check it once (in case if you dont get answer)

happy coding

its correct, it just doesn't make any sense. it 'll cause the loop never to be executed, but if that's what the OP was going for ...
(although I suspect he may have intended the second 0 to actually be his o variable)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.