• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Declaring Multiple Private Variables

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 23901
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes that worked! Your input was extremely helpful
 
Sheriff
Posts: 22262
119
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic