0
A doubt with repeated numbers 😃
Is the next: Read a sequence of integers and determine the first number that appears repeated 3 times consecutively I have been advised to use the "while" and the "if else" but i dont know how. Im a noob xD I would appreciate if someone helps me .
1 ответ
0
You'll probably need a Scanner to read in the integers, one by one. First, initialize a variable last_number to some dummy value, and a variable counter to 0. While this Scanner successfully gets a number (that is, it doesn't get an EOF), the loop could look like this:
- compare the newly-read integer to last_number. If they're equal, add 1 to the counter. If they're different, reset counter to 0.
- if counter reaches 3, you're done: you may print the number and exit the loop.
- set last_number to the actual number, and read the next integer.