1,105,214 Community Members

Cannot find symbol

Member Avatar
bhadra.anurag
Newbie Poster
1 post since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
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.

Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
0
 

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

Member Avatar
adikimicky
Light Poster
37 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

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);
Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
1
 

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.

Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
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

Member Avatar
stultuske
Posting Expert
5,292 posts since Jan 2007
Reputation Points: 935 [?]
Q&As Helped to Solve: 775 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

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)

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: