We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Cannot find symbol

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.

6
Contributors
5
Replies
6 Days
Discussion Span
4 Months Ago
Last Updated
6
Views
bhadra.anurag
Newbie Poster
1 post since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

mvmalderen
Posting Maven
2,612 posts since Feb 2009
Reputation Points: 2,221
Solved Threads: 281
Skill Endorsements: 36

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);
adikimicky
Light Poster
37 posts since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

mvmalderen
Posting Maven
2,612 posts since Feb 2009
Reputation Points: 2,221
Solved Threads: 281
Skill Endorsements: 36

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

radhakrishna.p
Posting Whiz in Training
272 posts since Nov 2012
Reputation Points: 29
Solved Threads: 60
Skill Endorsements: 11

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)

stultuske
Industrious Poster
4,489 posts since Jan 2007
Reputation Points: 1,377
Solved Threads: 628
Skill Endorsements: 25

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0684 seconds using 2.65MB