Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Declaring Multiple Private Variables

 
Reno Madrigal
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried compiling it? You will noticed that your declaration will not work. I believe you want this...



Henry
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Reno Madrigal
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that worked! Your input was extremely helpful
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, please note that your code will be much more readable if you declare each variable on its own line:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic