Vous êtes sur la page 1sur 9

Problema 11: Imprimir un histograma de las edades del curso MA713 el numero de asteriscos corresponde con el nmero de alumnos

de las edades entre 15 y 25 aos. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 } run: 0 1 0 2 7 10 12 8 4 2 1 15 16 * 17 18 ** 19 ******* 20 ********** 21 ************ 22 ******** 23 **** 24 ** 25 * GENERACIN CORRECTA (total time: 1 minute 8 seconds) } } Scanner s = new Scanner(System.in); int []A = new int[11]; for(int i=0; i<11; i++) A[i]=s.nextInt(); for(int i=0; i<11; i++) { System.out.print(i+15+" "); for(int j=0; j<A[i]; j++) System.out.print("*"); System.out.println(); { public class Main { public static void main(String[] args) package problema11; import java.util.Scanner;

Problema 7: Cargar el arreglo A n*m, el arreglo Bm*p. Hallar el producto AxB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 } run: 212 3 6 2 4 El producto de la matriz AxB es: 6 12 12 24 GENERACIN CORRECTA (total time: 8 seconds) } } System.out.println("El producto de la matriz AxB es: "); for(int i=0; i<m; i++) { for(int j=0; j<p; j++) System.out.print(C[i][j]+" "); System.out.println(); for(int i=0; i<m; i++) for(int j=0; j<p; j++) for(int k=0; k<n; k++) C[i][j]+=A[i][k]*B[k][j]; for(int i=0; i<n; i++) for(int j=0; j<p; j++) B[i][j]=s.nextInt(); public class Main { public static void main(String[] args) { int m,n,p; Scanner s= new Scanner(System.in); m = s.nextInt(); n = s.nextInt(); p = s.nextInt(); int [][]A = new int [m][n]; int [][]B = new int [n][p]; int [][]C = new int [m][p]; for(int i=0; i<m; i++) for(int j=0; j<n; j++) A[i][j]=s.nextInt(); package problema7; import java.util.Scanner;

Problema 1: Imprimir la lista cargada con nmeros de la serie Fibonacci, mtodo visualizar() 0,1,1,2,3,5 Leer la cantidad de nmeros a sumar, usar mtodo Fibo() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 } run: 6 0, 1, 1, 2, 3, 5 GENERACIN CORRECTA (total time: 6 seconds) } } static void Fibo(int n, int A[]) { if(n<2) return; for(int i=2; i<n; i++) A[i]=A[i-1]+A[i-2]; static void visualizar(int A[], int n){ for(int i=0; i<n-1; i++) System.out.print(A[i]+", "); System.out.println(A[n-1]); } public class Main { public static void main(String[] args) { // TODO code application logic here int n; Scanner Obj = new Scanner(System.in); n = Obj.nextInt(); int []A = new int[100]; A[0]=0; A[1]=1; Fibo(n,A); visualizar(A, n); import java.util.Scanner; package problema1;

Problema 2: Determinar la suma y promedio de los n primeros nmeros primos comprendidos entre 1 y 100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 } run: 5 La suma de los 5 primeros primos es 28.0 El promedio de los 5 primeros primos es 5.6 GENERACIN CORRECTA (total time: 4 seconds) } } promedio=suma/n; System.out.println("La suma de los "+n+" primeros primos es "+suma); System.out.println("El promedio de los "+n+" primeros primos es "+promedio); } j++; int i=0; int j=2; float suma=0; float promedio=0; while(i<n) { if(A[j]==0) { i++; suma+=j; } } public class Main { public static void main(String[] args) { Scanner Obj = new Scanner(System.in); int n = Obj.nextInt(); int A[] = new int[100]; for(int i=2; i<Math.sqrt(100); i++) { int j=i+i; while(j<100) { A[j]=1; j+=i; import java.util.Scanner; package problema2;

Problema 3: Se tiene 2 listas An y Bm ordenados con datos, obtener la lista Cn+m combinando los elementos de A y B 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 } run: 4 1234 5 56789 1 2 3 4 5 6 7 8 9 GENERACIN CORRECTA (total time: 10 seconds) } } for(int k=0; k<n+m; k++) System.out.print(C[k]+" "); } int []C = new int [n+m]; int i=0,j=0; for(int k=0; k<n+m; k++) { if(i>=n) C[k]=B[j++]; else if(j>=m) C[k]=A[i++]; else{ if(A[i]<B[j]) C[k]=A[i++]; else C[k]=B[j++]; int m = Obj.nextInt(); int []B = new int [m]; for(int i=0; i<m ; i++) B[i] = Obj.nextInt(); public class Main { public static void main(String[] args) { Scanner Obj = new Scanner(System.in); int n = Obj.nextInt(); int []A = new int [n]; for(int i=0; i<n ; i++) A[i] = Obj.nextInt(); import java.util.Scanner; package problema3;

Problema 5: Leer un mensaje y determinar el numero de palabras que tiene, cuantas letras y la palabra de mayor longitud 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 } run: Hola como estas La frase tiene 3 palabras La palabra de mayor longitud tiene 5 letras GENERACIN CORRECTA (total time: 10 seconds) } } words[k]=msg.substring(a, msg.length()); return words; } } String[] words = new String[n+1]; //String[] words = new String[100]; int a=0; int k=0; for(int i=0; i<msg.length(); i++){ if(msg.charAt(i)==' '){ words[k++]=msg.substring(a, i); a=i+1; System.out.println("La frase tiene "+palabras.length+" palabras"); int mayor=palabras[0].length(); for(int i=1; i<palabras.length; i++) if(mayor<palabras[i].length()) mayor=palabras[i].length(); System.out.println("La palabra de mayor longitud tiene "+mayor+" letras"); } static String [] split(String msg){ int n=0; for(int i=0; i<msg.length(); i++){ if(msg.charAt(i)==' ') n++; package problema5; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner Obj = new Scanner(System.in); String msg = Obj.nextLine(); String []palabras = split(msg); //String []palabras = msg.split(" ");

Problema 6: Leer un arreglo de n nmeros enteros entre 500 y 1500 ordenar de mayor a menor, utilizando el algoritmo de quicksort 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 } static int particion(int []A, int i, int j ){ /*if(i<j) return i;*/ int pivot=A[i]; int r = i; } } else { quicksort(A,i,r-1); quicksort(A,r+1,j); } else if(j==r )//|| r==j-1) { quicksort(A,i,r-1); int r=particion(A,i,j); if(i==r )//|| r==i+1) { quicksort(A,r+1,j); if(i==j) return; static void quicksort(int[] A, int i, int j) { } quicksort(A,0,n-1); for(int i=0; i<n; i++) System.out.print(A[i]+" "); public class Main { public static void main(String[] args) { Scanner Obj = new Scanner(System.in); int n = Obj.nextInt(); int []A = new int [n]; for(int i=0; i<n; i++) A[i]=Obj.nextInt(); import java.util.Scanner; package problema6;

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 } run: 4 }

for(int k=i; k<=j; k++) { if(pivot>A[k]) { int temp=A[k]; int t=k; while(t>r) { A[t]=A[t-1]; t--; } r++; A[r-1]=temp; } } return r;

76 48 94 23 23 48 76 94 GENERACIN CORRECTA (total time: 11 seconds)

Problema 9: leer un mensaje por pantalla y encriptar el mensaje utilizando el cdigo cesar que consiste en hacer un corrimiento de 5 posiciones del carcter alfabetico 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 } run: lunes qzsjx GENERACIN CORRECTA (total time: 4 seconds) } } String nc = new String(encr); System.out.println(encr); for(int i=0; i<msg.length(); i++) { int tmp = msg.charAt(i); tmp = (tmp - (int) 'a'); tmp = (tmp+5)%26; tmp = tmp + (int)'a'; encr[i]=(char)(tmp); public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); String msg = s.nextLine(); char []encr = new char[msg.length()]; import java.util.Scanner; package problema9;

Vous aimerez peut-être aussi