Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package examen_programacion_Antonio_Villena;
  2.  
  3. public class Examen_ejer01_Antonio_Villena {
  4. private static int[] array = new int[10];
  5.  
  6. private static void cargar() {
  7. for(int i = 0; i < array.length; i++) {
  8. int r = ((int) ((Math.random()*100)+1));
  9.  
  10. array[i] = r;
  11. }
  12. }
  13.  
  14. private static void mostrar() {
  15. for(int i = 0; i < array.length; i++) {
  16. System.out.println("Índice "+i+" \b"+array[i]);
  17. }
  18. }
  19.  
  20. private static void rotar(int numeroPos) {
  21. for(int x = 0; x < numeroPos; x++) {
  22. moverPos(array[x], x+1, array.length-1);
  23. }
  24. }
  25.  
  26. private static void moverPos(int valor, int pos, int cuenta) {
  27. if(pos == array.length) pos = 0;
  28.  
  29. int aux = array[pos];
  30. array[pos] = valor;
  31.  
  32. if(cuenta > 0) moverPos(aux, pos+1, cuenta-1);
  33. }
  34.  
  35. public static void run() {
  36. cargar();
  37. mostrar();
  38. rotar(2);
  39. System.out.println();
  40. mostrar();
  41. }
  42.  
  43.  
  44. public static void main(String[] args) {
  45. run();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement