fork download
  1. import java.util.*;
  2.  
  3. public class Main{
  4. public static void main(String []args){
  5. String num = "1432219";
  6. int k = 3;
  7. int length = num.length();
  8. int size = length - k;
  9. int top = 0;
  10. ArrayList<Integer> mine = new ArrayList<Integer>();
  11. for ( int i =0; i < length; i ++){
  12. int temp = Character.getNumericValue(num.charAt(i));
  13. mine.add(temp);
  14. }
  15.  
  16.  
  17. for (int i = 0; i < length; i ++ ){
  18. if((i!=0) && (num.charAt(i) > num.charAt(i-1)) && (k != 0)){
  19.  
  20. for(int j = 0; j < k; j ++){
  21. mine.remove(i+j);
  22. }
  23. }
  24. }
  25.  
  26. System.out.println(mine);
  27. }
  28. }
Runtime error #stdin #stdout #stderr 0.11s 34092KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 4
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:372)
	at java.base/java.util.ArrayList.remove(ArrayList.java:535)
	at Main.main(Main.java:21)