Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] tmp = { 0, 45, 6, 0, 56, 7, 0 };
- int numZeri=0;
- for (int i = 0; i < tmp.length; i++) {
- if (tmp[i] == 0 && i < tmp.length - 1) {// sposto tutto a destra di 1 posizione
- for (int j = i; j < tmp.length-1; j++) {
- tmp[j] = tmp[j + 1];
- }
- numZeri++;
- }
- }
- int posZeri = tmp.length -numZeri;
- for (int i = posZeri; i < tmp.length; i++) {
- tmp[i] = 0;
- }
- for (int i = 0; i < tmp.length; i++) {
- System.out.println(tmp[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement