I have worked at this exercise for several hours... and finally generated the output that seems to fulfill the task requirements and, yet, no-go!
If anyone can see any hidden clues to my situation in my code I would love some advice! : )
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
// The program should read values from the keyboard.
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// In the main method, declare an ArrayList variable with Integer elements and immediately initialize it.
ArrayList<Integer> integerElements = new ArrayList<Integer>();
while (true) {
String s = reader.readLine();
if (s.isEmpty()) break;
int a = Integer.parseInt(s);
// The program should add 10 numbers to the collection in accordance with the conditions.
integerElements.add(a);
}
// Reset the counter if a different number emerges, but record the current record (You don't need to record which number it was.)
int currentRecord = 1;
int absoluteRecord = 1;
for(int i = 0; i < 9; i++) {
if (integerElements.get(i) == integerElements.get(i + 1) && i != 8) {
currentRecord = currentRecord + 1;
} else if((integerElements.get(i) == integerElements.get(i + 1) && i == 8)){
currentRecord = currentRecord + 1;
if (currentRecord > absoluteRecord) {
absoluteRecord = currentRecord;
currentRecord = 1;
} else {}
}else if(integerElements.get(i) != integerElements.get(i + 1)){
//If get(i) doesn't match get(i+1), run this code.
//This value doesn't match the next one. Record its streak if it's the new record.
if (currentRecord > absoluteRecord) {
absoluteRecord = currentRecord;
currentRecord = 1;
} else {
//If the currentRecord is not greater than the absoluteRecord, return to the loop.
currentRecord = 1;
}
}
}
System.out.println(absoluteRecord);
}
}
package com.codegym.task.task10.task1004;
/*
Task No. 4 about integer type conversions
*/
public class Solution {
public static void main(String[] args) {
short number = (char) 9;
System.out.println("This is number nine..." + number);
char zero = (byte) '0';
System.out.println("This is number zero..." + zero);
int nine = (char) ( zero + number);
System.out.println(nine);
}
}