Two Laptop Bag*
The moose likes Beginning Java and the fly likes Declaring Multiple Private Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Declaring Multiple Private Variables " Watch "Declaring Multiple Private Variables " New topic
Author

Declaring Multiple Private Variables

Reno Madrigal
Greenhorn

Joined: Sep 24, 2007
Posts: 18
This question is either really naive or just not possible

Here is what ive typed into Jcreator Pro:

//VARIABLE TO HOLD Candidate CHOICE

private int choice = 0; count1; count2;
count3; count4; count5; count6; count7; maxVote;


My question is, when having multiple variables am I to use ";" just to separate them or after the private int choice = 0 am I suppose to stop? If you need more info about this problem, it is a voting one so each variable represents a different candidate and soforth. I am just confused at adding more than 1 variable since we havent got that far. Thanks!

Also 1 more quick question:

Here is what I have written~~~


public void beginVote()
{
do
call getVote()
switch(choice)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7: call tallyVote()


I am unsure as what to do when I call another subject, am I to start that underneath like so? For instance, when I call does that mean I should input my getVote code before I get to switchChoice? Same with tallyvote.


public void beginVote()
{
do
call getVote()
\\DO GET vOTE HERE?\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

switch(choice)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7: call tallyVote()
\\\\\\\\\\\\\\\\\\\\\\\\\DO Tallyvote here?\\\\\\\\\
[ September 24, 2007: Message edited by: Reno Madrigal ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19063
    
  40

Have you tried compiling it? You will noticed that your declaration will not work. I believe you want this...



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

After your access modifier (private) and type (int), you can declare multiple variables in the same line (before the ending semicolon) by separating them with commas.

I'm not sure I understand your second question, but the order of defining and calling a method does not matter.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Reno Madrigal
Greenhorn

Joined: Sep 24, 2007
Posts: 18
Yes that worked! Your input was extremely helpful
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

However, please note that your code will be much more readable if you declare each variable on its own line:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Declaring Multiple Private Variables