This obviously is incorrect and it something I wrote but I want to know if using
ID: 3638899 • Letter: T
Question
This obviously is incorrect and it something I wrote but I want to know if using what I already have is there a way to check for duplicates and display them this is the problem: (Same-number subsequence) Write an O(n) program that prompts users to enter a sequence of integers ending with 0's and finds the longest subsequence with the same number. For example lets say I entered 122220 it starts at index 1 and has four values of 2
import java.util.Collections;
import java.util.Scanner;
public class Longest_Same_SubSequence {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter a series of numbers ending with 0");
int n = scan.nextInt();
java.util.List<Integer> list = new java.util.ArrayList<Integer>(n);
list.add(n);
int e = list.get(list.size()-1);
for(int i = list.indexOf(0); i<e; i++){
list.listIterator(list.indexOf(i));
System.out.println("" + i);
}
}
}