Vous êtes sur la page 1sur 4

EJERCICIOS DE ARREGLOS JAVA NOTA: SI EN EL EXAMEN LLEGA A SALIR UN EJERCICIO DE ESTO O SIMILAR POR FAVOR AGREGALE A TU PROGRAMA UN PAR

DE TOQUES PERSONALES . Este es un programa donde: Crear el arreglo, mostrar el arreglo, listar el arreglo y ordena de mayor a menor los datos numricos. import java.io.*; public class OrdenamientoMayor{ public static void main (String[] args) throws IOException{ BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in)); int dimension; int A[]; System.out.print("Dame el tamao del arreglo ? "); dimension = Integer.parseInt(teclado.readLine()); A = new int[dimension]; // Insertamos datos en el arreglo A for (int i = 0; i< dimension; i++) { System.out.print("Dame valor posicion "+i+" : "); A[i] = Integer.parseInt(teclado.readLine()); } // Mostramos el arreglo A for (int i = 0; i< dimension; i++) { System.out.println("A["+i+"] = "+A[i]); } // Ordenamiento de Mayor a Menor for (int i = 0; i <= dimension - 2 ; i++) { for (int j = i+1; j <= dimension -1; j++) { if(A[i] < A[j]){ int tempo = A[i]; A[i] = A[j]; A[j] = tempo; } } } System.out.println(" *******ORDENADO DE > A < *********"); // Mostramos el arreglo A Ordenado de Mayor a Menor for (int i = 0; i< dimension; i++) { System.out.println("A["+i+"] = "+A[i]); }

Este es un programa donde: Crear el arreglo, mostrar el arreglo, listar el arreglo y mostrar el arreglo de forma invertida es decir: 2 4 6 8 10; 10 8 6 4 2! import java.io.*; public class CopiaInvertida{ public static void main (String[] args) throws IOException{ BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in)); int dimension; int A[]; int B[]; System.out.print("Dame el tamao del arreglo ? "); dimension = Integer.parseInt(teclado.readLine()); A = new int[dimension]; B = new int[dimension]; // Insertamos datos en el arreglo A for (int i = 0; i< dimension; i++) { System.out.print("Dame valor posicion "+i+" : "); A[i] = Integer.parseInt(teclado.readLine()); } // Mostramos el arreglo A for (int i = 0; i< dimension; i++) { System.out.println("A["+i+"] = "+A[i]); } // Copia invertida en arreglo B for (int i = 0,j = dimension-1 ; i< dimension; i++, j--) { B[j] = A[i]; } System.out.println(" ***************"); // Mostramos el arreglo B for (int i = 0; i< dimension; i++) { System.out.println("B["+i+"] = "+B[i]); } } }

Este es un programa donde: Crear el arreglo, mostrar el arreglo, listar el arreglo y mostrar la suma de los valores import java.io.*; public class SumaArreglo { public static void main (String[] args) throws IOException{ BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in)); int dimension; int A[]; int suma = 0; System.out.print("Dame el Tamao del Arreglo ? "); dimension = Integer.parseInt(teclado.readLine()); A = new int[dimension]; for (int i = 0; i < dimension; i++) { System.out.print("Dame valor posicion No. "+i+" : "); A[i] = Integer.parseInt(teclado.readLine()); } for (int i = 0; i < dimension; i++) { System.out.print(" "+A[i]); } // Sumamos los elementos del arreglo for (int i = 0; i < dimension ; i++) { suma = suma + A[i]; } System.out.println(""); System.out.println("**** SUMA DE ARREGLO ****"); System.out.println("Total Suma = "+suma); } }

Un programa que me pida un nmero entero de valores y qu e posea un multiplicador


import java.io.*; public class MultiplicadorArreglos{ public static void main (String[] args) throws IOException{ BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in)); int multiplicador; int dimension; int A[]; int B[]; System.out.print("Dame el tamao del arreglo ? "); dimension = Integer.parseInt(teclado.readLine()); A = new int[dimension]; B = new int[dimension]; System.out.print("Dame el Multiplicador para el arreglo ? "); multiplicador = Integer.parseInt(teclado.readLine()); // Insertamos datos en el arreglo A for (int i = 0; i< dimension; i++) { System.out.print("Dame valor posicion "+i+" : "); A[i] = Integer.parseInt(teclado.readLine()); } // Mostramos el contenido del Arreglo A for (int i = 0; i< dimension; i++) { System.out.println("A["+i+"] = "+A[i]); } // Multiplicamos los campos del arreglo A por el multiplicador // y asignamos los valor al arreglo B for (int i = 0; i< dimension; i++) { B[i] = A[i] * multiplicador; } System.out.println(" *********************"); // Mostramos el contenido del Arreglo B for (int i = 0; i< dimension; i++) { System.out.println("B["+i+"] = "+B[i]); } } }

Vous aimerez peut-être aussi