aspose file tools*
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""cannot find symbol variable..."" Watch ""cannot find symbol variable..."" New topic
Author

"cannot find symbol variable..."

Evan Cristofori
Greenhorn

Joined: Feb 02, 2007
Posts: 18
Hello Everyone,

I am a new Java student and I am having some troubles on my second assignment:

Write a simple Java program (using the template HelloWorld.java again if you wish). Your program should be named "Variable.java", and the class in it should be named "Variable". Please submit both the .java file and the .class file; make sure your program compiles and runs on arizona.edu.
 
The main( ) method in your program should contain two parts:
 
Part 1

Declare two integer variables and name them num1 and num2 respectively;
Assign the value 17 to num1 and 9902 to num2;
Compute the precise average of their product and their sum, store the result into a variable named res;
Print in the result in the following form ("X" is just a placeholder; the real output should substitute it with the result of the calculation above):
 
The result is X.
 
Part 2
 
Declare three character variables named var1, var2, and var3 respectively;
Store the character "a" into var1, "b" into var2, and "c" into var3;
Print the following output, without using literal characters "a", "b" and "c" in the print() or println() method:
 
(a) (b) (c)


Here is what I have so far:



When I try to compile I get the error: "cannot find symbol variable a". The same for b, and c. What could I do to correct this error?

Thank You
Evan
[ February 02, 2007: Message edited by: Evan Cristofori ]
Raguel Koning
Greenhorn

Joined: May 17, 2006
Posts: 12
Have a look at the following tutorials on Datatypes...

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html

You are basically declaring an int variable, but instead of putting an int value into it you are putting a string literal in there...

Compare:

int var1 = 1; with int var1 = b;
Evan Cristofori
Greenhorn

Joined: Feb 02, 2007
Posts: 18
I am still confused as to where I made the error.
Raguel Koning
Greenhorn

Joined: May 17, 2006
Posts: 12
Hi again :-)

Your assignment says: "Declare three character variables named var1, var2, and var3 respectively;
Store the character "a" into var1, "b" into var2, and "c" into var3;
Print the following output, without using literal characters "a", "b" and "c" in the print() or println() method:"

Ok?
So lets first look at the 8 primitive datatypes for Java:

boolean
char

byte
short
int
long

float
double

You are saying: create me ant integer (int) and put a character in it...
You can't do that you have to say something like

char var1 = 'a';

instead of

int var1 = a;

An int is numeric, it is not a character.
Evan Cristofori
Greenhorn

Joined: Feb 02, 2007
Posts: 18
Hi,

Alright, I understand that much now, thanks. How would I do this part of the assignment?

Print the following output, without using literal characters "a", "b" and "c" in the print() or println() method

[ February 02, 2007: Message edited by: Evan Cristofori ]
[ February 02, 2007: Message edited by: Evan Cristofori ]
Evan Cristofori
Greenhorn

Joined: Feb 02, 2007
Posts: 18
Any help?

=[
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
What's your code look like now and what kind of errors are you getting?
Evan Cristofori
Greenhorn

Joined: Feb 02, 2007
Posts: 18
Here is what I got now:



I am getting an error that reads... "cannt find symbol class var1 and var2"

The assignment was posted above...

I am having problems with this part:
Print the following output, without using literal characters "a", "b" and "c" in the print() or println() method

Thanks
[ February 03, 2007: Message edited by: Evan Cristofori ]
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
The line with the error is presumably :

System.out.println("(var1) (var2) (var3)");

The syntax is incorrect. Specifically this part is problematic: (var1) (var2) (var3)

Why don't you try printing the three values out individually. (Three println statements.)
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi Evan,

you can glue Strings and chars together with the + operator.
The following lines print the same:

output is
letter a.
letter a.

So you can do something with "(" and ")".


Something else, the question said "Declare two integer variables...".
So you must not take floats, but ints.

Yours,
Bu.
Evan Cristofori
Greenhorn

Joined: Feb 02, 2007
Posts: 18
Thank you all for your help.

Assignment has been submitted...

Yay!

-Evan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "cannot find symbol variable..."