-
What's wrong with my code?? (it said cannot resolve symbol)
Here is my code:
Quote:
import java.util.*;
public class Coin {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("How many times you want to flip?");
int time=input.nextInt();
int array[]=new int[time];
int showtime[]=new int[10];
int head=0,tail=0,most=0;
String output="";
System.out.println("Generate: ");
for (int x=0;x<time;x++) {
int a=(int) (Math.random()*10+1);
System.out.print(a+" , ");
array[x]=a;
showtime[a-1]++;
if (a%2==0) head++;
else tail++;
}
System.out.println();
for (int x=0;x<10;x++) {
System.out.println("No. \""+(x+1)+"\" showed "+showtime[x]+" time(s)");
if (showtime[x]>showtime[most]) {
most=x;
output="The number(s) that showed up the most: "+(x+1);
}
else if (showtime[x]==showtime[most])
output=output+" , "+(x+1);
}
System.out.println(output);
if (head>tail) System.out.println("Heads came up the most");
else if (head==tail) System.out.println("Heads=Tails");
else System.out.println("Tails came up the most");
}
}
What's wrong with my code??
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
I just tested out the code using eclipse, and everything works fine for me! Check to see if there are any comments using strange symbols. Other than that, the code you posted is solid and works fine!
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Please post the full text of the error message.
-
1 Attachment(s)
Re: What's wrong with my code?? (it said cannot resolve symbol)
Attachment 1272
Here is the error message.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Please post the full text here so parts can be selected for searches etc.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Why can't it find the Scanner class?
Try adding
import java.util.Scanner;
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Quote:
Originally Posted by
javapenguin
Why can't it find the Scanner class?
Try adding
import java.util.Scanner;
He has though, and that should cover it.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
:-??:-??:-??:-??
It compiles for me as is.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Try adding import java.util.Scanner; anyway. If the Scanner class cannot be found for some reason, it will throw an error at the import statement. If that does happen, this is a problem with your environment.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
The OP has not said what is wrong with his code. What symbol is the problem?
Don't we need that to be able to make suggestions?
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
It is still not working. It said that cannot resolve the scanner class....:(
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Please copy full text of error message and paste it here. Here is a sample:
Code :
TestSorts.java:138: cannot find symbol
symbol : variable var
location: class TestSorts
var = 2;
^
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
When I add "import java.util.Scanner;" it creates another error.... saying error on the Scanner class.....
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Please post the full text of the compiler's error message.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
My error:
Code :
flip.java:7: cannot resolve symbol
symbol : class Scanner
location: class flip
Scanner input=new Scanner(System.in);
^
flip.java:7: cannot resolve symbol
symbol : class Scanner
location: class flip
Scanner input=new Scanner(System.in);
^
2 errors
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
What version of the JDK are you using? The Scanner class came with version 1.5
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
mine is 1.4.2. So what can I do??
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Either rewrite the code to use classes available in version 1.4
or download and install a newer version of the JDK.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
I think some syntax problem can you send me complete coding which are using in your program.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
@programmingtutorials The code as posted compiles with JDKs 1.5 and later.
To see the OPs problem, try compiling the posted code with JDK 1.4
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
so, what can I do to replace the Scanner class in my 1.4.2 version?? How do I do it??
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Start with System.in. Find a wrapper class to wrap it and that can be wrapped in the BufferedReader class.
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Is there any examples?? Like how do I start? I forgot how to do a wrapper class:P
-
Re: What's wrong with my code?? (it said cannot resolve symbol)
Something like this:
BuffferedReader br = new BufferedReader(new WrapperClass(System.in));
You need to read the API doc to find what is the correct class for WrapperClass.