fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int count = 1;
  13. int largest = 0;
  14. int[] numb = {1,1,2,1,1,1 };
  15. int key = 1;
  16.  
  17. for (int i = 0; i<numb.length; i++){
  18. for(int j = i + 1; j<numb.length;j++){
  19. if(numb[i] == numb[j]){
  20. count++;
  21. }else{
  22. if(largest<count) {
  23. largest = Math.max(largest, count);
  24. count = 0;
  25. }
  26. }
  27. }
  28.  
  29. }
  30. System.out.println("Largest number of consecutive times "+key+" was entered: "+largest);
  31. }
  32. }
Success #stdin #stdout 0.03s 711168KB
stdin
Standard input is empty
stdout
Largest number of consecutive times 1 was entered: 3