PDA

View Full Version : symbol unknown or something like that


pacotens
09-07-2007, 06:46 PM
Here is a mistake cmd shows in most of my programs:

my [code]

[\import java.io.*;
import javagently.*;

public class P604{
public static void main(String args[]) throws IOException{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(isr);
String query=in.readLine();
int startpositie=0;
do{
int positie=query.indexOf('&',startpositie);
if (positie>0){
String tijdelijk=query.substring(startpositie,positie);
startpositie=(positie+1);
}
else {
String tijdelijk=query.substring(startpositie,query.length());
}
int positieGelijk=tijdelijk.indexOf('=');
StringBuffer tijdelijk2= new StringBuffer(tijdelijk);
tijdelijk2.setCharAt(positieGelijk,',');
int startpositieplus=0;
do{
int positiePlus=tijdelijk.indexOf('+',startpositieplus);
if (positiePlus>=0){
tijdelijk2.setCharAt(positiePlus,' ');
startpositieplus=(positiePlus+1);}
}while(positiePlus>=0);
System.out.println("("+tijdelijk2+")");
}while(positie>0);
}
}
]

the errors are according to cmd:

D:\Java>javac P604.java
P604.java:19: cannot find symbol
symbol : variable tijdelijk
location: class P604
int positieGelijk=tijdelijk.indexOf('=');
^
P604.java:20: cannot find symbol
symbol : variable tijdelijk
location: class P604
StringBuffer tijdelijk2= new StringBuffer(tijdelijk);
^
P604.java:24: cannot find symbol
symbol : variable tijdelijk
location: class P604
int positiePlus=tijdelijk.indexOf('+',startpositieplus);

^
P604.java:28: cannot find symbol
symbol : variable positiePlus
location: class P604
}while(positiePlus>=0);
^
P604.java:30: cannot find symbol
symbol : variable positie
location: class P604
}while(positie>0);
^
5 errors

thx in advance

brad211987
09-07-2007, 07:18 PM
At this point in your code:


if (positie>0)
{
String tijdelijk=query.substring(startpositie,positie);
startpositie=(positie+1);
}
else
{
String tijdelijk=query.substring(startpositie,query.length());
}


You define a variable 'tijdelijk' but the scope of this variable does not reach outside of these blocks of code. You need to define the variable outside of the if/else statements, and set the variable within them. Meaning, before your if statement, you could put:

String tijdelijk = "";

That would make the variable accessible from other parts of your code, specifically the area that you are attempting to use it.

pacotens
09-09-2007, 04:25 PM
thx now my program works