• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"cannot find symbol variable..."

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still confused as to where I made the error.
 
Raguel Koning
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any help?

=[
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's your code look like now and what kind of errors are you getting?
 
Evan Cristofori
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your help.

Assignment has been submitted...

Yay!

-Evan
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic