GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes example of count++ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "example of count++" Watch "example of count++" New topic
Author

example of count++

djsami mukhtar
Greenhorn

Joined: May 02, 2004
Posts: 9
hi
can someone give me a simple example of how to read different sets of inputs..counts the matching inputs and outputs the number they have reoccured..
o.k..lets hypethitically say..i wana input 3 different types of cows; black, brown and white..and wana count how many times they have been inputed and output them by saying black cows 3 brown cows 4..etc
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
djsami mukhtar
Greenhorn

Joined: May 02, 2004
Posts: 9
thanks Marilyn
i have done something similar but its not working,i'm try tocount and then catgorize grades instead of cows would i be better off with arrays u think.. can you see where i went wrong?
public class GradeCount
{


public static void main (String[] args)


int grade, count = 0, sum = 0;





System.out.println ("Enter the first Grade");
grade = Keyboard.readInt();

while( grade = 90 && < 100)

{
count++;
sum += grade;
System.out.println (" Number of A's = "+ count);

}

while( grade = 80 && < 89)

{
count++;
sum += grade;
System.out.println (" Number of B's = "+ count);

}

while( grade = 70 && < 79)

{
count++;
sum += grade;
System.out.println (" Number of C's = "+ count);

}


while( grade = 60 && < 69)

{
count++;
sum += grade;
System.out.println (" Number of D's = "+ count);

}

while( grade = 0 && < 59)

{
count++;
sum += grade;
System.out.println (" Number of F's = "+ count);

}
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10

Well, you could use arrays, but I think it is unnecessary. I think you might want to keep the count of each grade separately rather than one count for the total number of all grades combined.

I also think you might run into problems using while instead of if. I would think you would get a stack overflow error with these while loops.

By the way, code tags are a good thing.
djsami mukhtar
Greenhorn

Joined: May 02, 2004
Posts: 9
hi
i'm getting these types of error: illegal start of expression, incompatible types, '}' expected, and finally cannot resolve symbol class Keyboard
the code is below..can any one help me eliminate these errors

import cs1.Keyboard;
public class GradeCount
{


public static void main (String[] args)

{

int grade, count = 0, sum = 0;





System.out.println ("Enter the first Grade");
grade = Keyboard.readInt();

if( grade = 90 && < 100)


count++;
sum += grade;
System.out.println (" Number of A's = "+ count);



if( grade = 80 && < 89)


count++;
sum += grade;
System.out.println (" Number of B's = "+ count);



if( grade = 70 && < 79)


count++;
sum += grade;
System.out.println (" Number of C's = "+ count);




if( grade = 60 && < 69)


count++;
sum += grade;
System.out.println (" Number of D's = "+ count);



if( grade = 0 && < 59)


count++;
sum += grade;
System.out.println (" Number of F's = "+ count);

}

}
 
GeeCON Prague 2014
 
subject: example of count++