# Using percent Modulus to calculate total number of even numbers from user input

sandy skiathitis

Greenhorn

Posts: 18

posted 5 years ago

Ok my assignment for class is to use the percent mod to calculate the total number of all the numbers and the total number of even numbers only. This should be done by using the user's input of their number.

the % "mod" operator

Input:

The first line of input will be a random list of integers the user will put it.

Output:

Return the total integers in the list and count of even integers.

Sample:

Input Output

3 4 10 12 1 0 6 78 7 #total: 9

#even: 6

...............................................................

this is what I got so far

the % "mod" operator

Input:

The first line of input will be a random list of integers the user will put it.

Output:

Return the total integers in the list and count of even integers.

Sample:

Input Output

3 4 10 12 1 0 6 78 7 #total: 9

#even: 6

...............................................................

this is what I got so far

sandy skiathitis

Greenhorn

Posts: 18

posted 5 years ago

so I redid it ummmmm here is the second version...please help i am getting more lost...

sandy skiathitis wrote:Ok my assignment for class is to use the percent mod to calculate the total number of all the numbers and the total number of even numbers only. This should be done by using the user's input of their number.

the % "mod" operator

Input:

The first line of input will be a random list of integers the user will put it.

Output:

Return the total integers in the list and count of even integers.

Sample:

Input Output

3 4 10 12 1 0 6 78 7 #total: 9

#even: 6

...............................................................

this is what I got so far

so I redid it ummmmm here is the second version...please help i am getting more lost...

Stephan van Hulst

Bartender

Posts: 6583

84

posted 5 years ago

Your for loop appears broken. Take a step back and write down in plain English what the program should do:

1) Read one line from user input

2) While the line has another integer:

2.1) Increase total count of integers

2.2) If the integer is even:

2.2.1) Increase total count of even integers

3) Print total count of integers and total count of even integers

Now solve each step separately. Test your program in between solving steps, and make sure it does what you expect it to do. For instance, print the line after step 1) to make sure it's the same as you've entered.

You seem to have trouble with step 2). Look in the Scanner class for a very useful method.

1) Read one line from user input

2) While the line has another integer:

2.1) Increase total count of integers

2.2) If the integer is even:

2.2.1) Increase total count of even integers

3) Print total count of integers and total count of even integers

Now solve each step separately. Test your program in between solving steps, and make sure it does what you expect it to do. For instance, print the line after step 1) to make sure it's the same as you've entered.

You seem to have trouble with step 2). Look in the Scanner class for a very useful method.

*The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.*

sandy skiathitis

Greenhorn

Posts: 18

posted 5 years ago

so i would have to use a while statement then an if statement but how to I implement the remainder or percent modulud operator? also would i have to do something specefically so that the program will be able to read more than one input the user puts in??? sorry this is my first programming class and first project of the semester...

Stephan van Hulst wrote:Your for loop appears broken. Take a step back and write down in plain English what the program should do:

1) Read one line from user input

2) While the line has another integer:

2.1) Increase total count of integers

2.2) If the integer is even:

2.2.1) Increase total count of even integers

3) Print total count of integers and total count of even integers

Now solve each step separately. Test your program in between solving steps, and make sure it does what you expect it to do. For instance, print the line after step 1) to make sure it's the same as you've entered.

You seem to have trouble with step 2). Look in the Scanner class for a very useful method.

so i would have to use a while statement then an if statement but how to I implement the remainder or percent modulud operator? also would i have to do something specefically so that the program will be able to read more than one input the user puts in??? sorry this is my first programming class and first project of the semester...

Stephan van Hulst

Bartender

Posts: 6583

84

sandy skiathitis

Greenhorn

Posts: 18

sandy skiathitis

Greenhorn

Posts: 18

posted 5 years ago

this is what I got..I am soooo close...how can I do the total number count...I got lost..can you help???

sandy skiathitis wrote:Stephan van Hulst wrote:Here's a skeleton:

I am so confused....the outline helped but I just dont know enough computer language to put it together... I am on the right track? but I have to use percent mod..or the remainder of mod...

this is what I got..I am soooo close...how can I do the total number count...I got lost..can you help???

Stephan van Hulst

Bartender

Posts: 6583

84

posted 5 years ago

Sandy, Scanner has a very useful method called hasNextInt().

Here's an almost complete solution:

Here's an almost complete solution: