Hello
I know that code is not perfect but it works. I try it so meny times and allways all was ok. Who know why it is not correct for codegym validator?
My plan:
1. Create table []
2. Add 10 number for table []
3. Sort table 1,2,2,.....4,4,4,7,7,..
4. Find longest sequence
5. Create ArrayList (we must do it)
6. Print number - longest sequence
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
int[] list = new int[10];
for(int i=0; i<10; i++)
{
list[i]=scanner.nextInt();
}
for (int i = 0; i < list.length - 1; i++) {
for (int j = 0; j < list.length - 1; j++) {
if (list[j] < list[j + 1]) {
int temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
int temsequence=0;
int temp1=list[0];
int temTempSequence=1;
for(int j=1; j<list.length - 1; j++)
{
if(list[j]==temp1)
{
temsequence++;
}
else
{
temp1=list[j];
if(temsequence>temTempSequence)
{
temTempSequence=temsequence;
}
}
}
ArrayList<Integer> array = new ArrayList<Integer>();
for(int k=1; k<list.length - 1; k++)
{
array.add(list[k]);
}
System.out.println(temTempSequence);
//write your code here
}
}