• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

example of count++

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
djsami mukhtar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

}

}
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic