SlideShare una empresa de Scribd logo
Problema 11: Imprimir un histograma de las edades del curso MA713 el numero de asteriscos corresponde con el
número de alumnos de las edades entre 15 y 25 años.
1 package problema11;
2 import java.util.Scanner;
3
4 public class Main
5 {
6 public static void main(String[] args)
7 {
8
9 Scanner s = new Scanner(System.in);
10 int []A = new int[11];
11 for(int i=0; i<11; i++)
12 A[i]=s.nextInt();
13 for(int i=0; i<11; i++)
14 {
15 System.out.print(i+15+" ");
16 for(int j=0; j<A[i]; j++)
17 System.out.print("*");
18 System.out.println();
19 }
20 }
21
22 }
23 run:
24 0
25 1
26 0
27 2
28 7
29 10
30 12
31 8
32 4
33 2
34 1
35 15
36 16 *
37 17
38 18 **
39 19 *******
40 20 **********
41 21 ************
42 22 ********
43 23 ****
44 24 **
45 25 *
46 GENERACIÓN CORRECTA (total time: 1 minute 8 seconds)
Problema 7: Cargar el arreglo A n*m, el arreglo Bm*p. Hallar el producto AxB
1 package problema7;
2 import java.util.Scanner;
3
4 public class Main
5 {
6 public static void main(String[] args)
7 {
8 int m,n,p;
9 Scanner s= new Scanner(System.in);
10 m = s.nextInt();
11 n = s.nextInt();
12 p = s.nextInt();
13 int [][]A = new int [m][n];
14 int [][]B = new int [n][p];
15 int [][]C = new int [m][p];
16 for(int i=0; i<m; i++)
17 for(int j=0; j<n; j++)
18 A[i][j]=s.nextInt();
19
20 for(int i=0; i<n; i++)
21 for(int j=0; j<p; j++)
22 B[i][j]=s.nextInt();
23
24 for(int i=0; i<m; i++)
25 for(int j=0; j<p; j++)
26 for(int k=0; k<n; k++)
27 C[i][j]+=A[i][k]*B[k][j];
28
29 System.out.println("El producto de la matriz AxB es: ");
30 for(int i=0; i<m; i++)
31 {
32 for(int j=0; j<p; j++)
33 System.out.print(C[i][j]+" ");
34 System.out.println();
35 }
36 }
37 }
38 run:
39 2 1 2
40 3
41 6
42 2
43 4
44 El producto de la matriz AxB es:
45 6 12
46 12 24
47 GENERACIÓN CORRECTA (total time: 8 seconds)
Problema 1: Imprimir la lista cargada con números de la serie Fibonacci, método visualizar() 0,1,1,2,3,5…
Leer la cantidad de números a sumar, usar método Fibo()
1 package problema1;
2
3 import java.util.Scanner;
4
5 public class Main
6 {
7 public static void main(String[] args)
8 {
9 // TODO code application logic here
10 int n;
11 Scanner Obj = new Scanner(System.in);
12 n = Obj.nextInt();
13 int []A = new int[100];
14 A[0]=0;
15 A[1]=1;
16 Fibo(n,A);
17 visualizar(A, n);
18 }
19
20 static void visualizar(int A[], int n){
21 for(int i=0; i<n-1; i++)
22 System.out.print(A[i]+", ");
23 System.out.println(A[n-1]);
24 }
25 static void Fibo(int n, int A[])
26 {
27 if(n<2)
28 return;
29 for(int i=2; i<n; i++)
30 A[i]=A[i-1]+A[i-2];
31 }
32 }
33 run:
34 6
35 0, 1, 1, 2, 3, 5
36 GENERACIÓN CORRECTA (total time: 6 seconds)
Problema 2: Determinar la suma y promedio de los n primeros números primos comprendidos entre 1 y 100
1 package problema2;
2
3 import java.util.Scanner;
4
5 public class Main
6 {
7 public static void main(String[] args)
8 {
9 Scanner Obj = new Scanner(System.in);
10 int n = Obj.nextInt();
11 int A[] = new int[100];
12 for(int i=2; i<Math.sqrt(100); i++)
13 {
14 int j=i+i;
15 while(j<100)
16 {
17 A[j]=1;
18 j+=i;
19 }
20 }
21
22 int i=0;
23 int j=2;
24 float suma=0;
25 float promedio=0;
26 while(i<n)
27 {
28 if(A[j]==0)
29 {
30 i++;
31 suma+=j;
32 }
33 j++;
34 }
35 promedio=suma/n;
36 System.out.println("La suma de los "+n+" primeros primos es "+suma);
37 System.out.println("El promedio de los "+n+" primeros primos es "+promedio);
38 }
39 }
40 run:
41 5
42 La suma de los 5 primeros primos es 28.0
43 El promedio de los 5 primeros primos es 5.6
44 GENERACIÓN CORRECTA (total time: 4 seconds)
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 package problema3;
2
3 import java.util.Scanner;
4
5 public class Main
6 {
7 public static void main(String[] args)
8 {
9 Scanner Obj = new Scanner(System.in);
10 int n = Obj.nextInt();
11 int []A = new int [n];
12 for(int i=0; i<n ; i++)
13 A[i] = Obj.nextInt();
14
15 int m = Obj.nextInt();
16 int []B = new int [m];
17 for(int i=0; i<m ; i++)
18 B[i] = Obj.nextInt();
19
20 int []C = new int [n+m];
21 int i=0,j=0;
22 for(int k=0; k<n+m; k++)
23 {
24 if(i>=n)
25 C[k]=B[j++];
26 else if(j>=m)
27 C[k]=A[i++];
28 else{
29 if(A[i]<B[j])
30 C[k]=A[i++];
31 else
32 C[k]=B[j++];
33 }
34 }
35 for(int k=0; k<n+m; k++)
36 System.out.print(C[k]+" ");
37 }
38 }
39 run:
40 4
41 1 2 3 4
42 5
43 5 6 7 8 9
44 1 2 3 4 5 6 7 8 9 GENERACIÓN CORRECTA (total time: 10 seconds)
Problema 5: Leer un mensaje y determinar el numero de palabras que tiene, cuantas letras y la palabra de mayor longitud
1 package problema5;
2 import java.util.Scanner;
3 public class Main
4 {
5 public static void main(String[] args)
6 {
7 Scanner Obj = new Scanner(System.in);
8 String msg = Obj.nextLine(); //String []palabras = msg.split(" ");
9 String []palabras = split(msg);
10
11 System.out.println("La frase tiene "+palabras.length+" palabras");
12 int mayor=palabras[0].length();
13 for(int i=1; i<palabras.length; i++)
14 if(mayor<palabras[i].length())
15 mayor=palabras[i].length();
16 System.out.println("La palabra de mayor longitud tiene "+mayor+" letras");
17 }
18 static String [] split(String msg){
19 int n=0;
20 for(int i=0; i<msg.length(); i++){
21 if(msg.charAt(i)==' ')
22 n++;
23 }
24 String[] words = new String[n+1];
25 //String[] words = new String[100];
26 int a=0;
27 int k=0;
28 for(int i=0; i<msg.length(); i++){
29 if(msg.charAt(i)==' '){
30 words[k++]=msg.substring(a, i);
31 a=i+1;
32 }
33 }
34 words[k]=msg.substring(a, msg.length());
35 return words;
36 }
37 }
38 run:
39 Hola como estas
40 La frase tiene 3 palabras
41 La palabra de mayor longitud tiene 5 letras
42 GENERACIÓN CORRECTA (total time: 10 seconds)
Problema 6: Leer un arreglo de n números enteros entre 500 y 1500 ordenar de mayor a menor, utilizando el algoritmo de
quicksort
1 package problema6;
2
3 import java.util.Scanner;
4
5 public class Main
6 {
7 public static void main(String[] args)
8 {
9 Scanner Obj = new Scanner(System.in);
10 int n = Obj.nextInt();
11 int []A = new int [n];
12 for(int i=0; i<n; i++)
13 A[i]=Obj.nextInt();
14
15 quicksort(A,0,n-1);
16 for(int i=0; i<n; i++)
17 System.out.print(A[i]+" ");
18 }
19
20 static void quicksort(int[] A, int i, int j) {
21
22 if(i==j)
23 return;
24
25 int r=particion(A,i,j);
26 if(i==r )//|| r==i+1)
27 {
28 quicksort(A,r+1,j);
29 }
30 else if(j==r )//|| r==j-1)
31 {
32 quicksort(A,i,r-1);
33 }
34 else
35 {
36 quicksort(A,i,r-1);
37 quicksort(A,r+1,j);
38 }
39
40
41 }
42 static int particion(int []A, int i, int j ){
43 /*if(i<j)
44 return i;*/
45 int pivot=A[i];
46 int r = i;
47 for(int k=i; k<=j; k++)
48 {
49 if(pivot>A[k])
50 {
51 int temp=A[k];
52 int t=k;
53 while(t>r)
54 {
55 A[t]=A[t-1];
56 t--;
57 }
58 r++;
59 A[r-1]=temp;
60 }
61 }
62 return r;
63 }
64 }
65 run:
66 4
67 76 48 94 23
68 23 48 76 94 GENERACIÓN CORRECTA (total time: 11 seconds)
Problema 9: leer un mensaje por pantalla y encriptar el mensaje utilizando el código cesar que consiste en hacer un
corrimiento de 5 posiciones del carácter alfabetico
1 package problema9;
2
3 import java.util.Scanner;
4
5 public class Main
6 {
7 public static void main(String[] args)
8 {
9 Scanner s = new Scanner(System.in);
10 String msg = s.nextLine();
11 char []encr = new char[msg.length()];
12
13 for(int i=0; i<msg.length(); i++)
14 {
15 int tmp = msg.charAt(i);
16 tmp = (tmp - (int) 'a');
17 tmp = (tmp+5)%26;
18 tmp = tmp + (int)'a';
19 encr[i]=(char)(tmp);
20 }
21 String nc = new String(encr);
22 System.out.println(encr);
23 }
24 }
25 run:
26 lunes
27 qzsjx
28 GENERACIÓN CORRECTA (total time: 4 seconds)

Más contenido relacionado

PDF
Arreglo hacer un programa para ingresar n valores reales en un arreglo y los ...
DOCX
Ejercicios java
DOCX
Ejercicios resueltos de programacion
PPTX
Semana 2 del 4 al 8 abril-ci
PPTX
Semana 3 del 11 15 abril-ci
PPTX
Practicar metodos
DOCX
ALGORITMOS EN JAVA
DOCX
Programas Propuestos Capítulo IV
Arreglo hacer un programa para ingresar n valores reales en un arreglo y los ...
Ejercicios java
Ejercicios resueltos de programacion
Semana 2 del 4 al 8 abril-ci
Semana 3 del 11 15 abril-ci
Practicar metodos
ALGORITMOS EN JAVA
Programas Propuestos Capítulo IV

La actualidad más candente (16)

DOCX
Algebra propedeutica
PPTX
Getchars
PPTX
Getchars
DOCX
Tra 130315111309-phpapp02
PPTX
Semana 2 c int -del 23 al 27 marzo
PPTX
Semana 2 del 1 al 5 abril-ci
DOCX
Evaluación prog iii try catch
PDF
ESTRUCTURA DE DATOS ALEXIS ROJAS
PPTX
Semana 9 del 24 al 28 de mayo
DOCX
Cuadrado y cubo de un numero
DOC
Programa en java para calcular promedios
DOCX
Graphmatematica vf
TXT
Programa 6
PPTX
Semana 11 c dif-del 7 al 11 de febrero 2022
PDF
Algebra propedeutica
Getchars
Getchars
Tra 130315111309-phpapp02
Semana 2 c int -del 23 al 27 marzo
Semana 2 del 1 al 5 abril-ci
Evaluación prog iii try catch
ESTRUCTURA DE DATOS ALEXIS ROJAS
Semana 9 del 24 al 28 de mayo
Cuadrado y cubo de un numero
Programa en java para calcular promedios
Graphmatematica vf
Programa 6
Semana 11 c dif-del 7 al 11 de febrero 2022
Publicidad

Similar a Ejercicios de programacion en java (20)

DOCX
Ejercicios resueltos de programacion
PDF
Ejercicios resuletos de programacion
DOCX
Recuperacion programas
DOCX
Bucles compuestos ejercicios en código java
DOCX
Recuperacion programas
DOCX
Practica 9
TXT
Programa 6
DOCX
Resolución de problemas con java
DOCX
Cecytem
DOCX
Manual de prácticas java 2015
PDF
colasEjeRe_1_2022.pdf
DOCX
Ejercicio 5
DOCX
Ejercicio 5
DOCX
Ejercicio 5
DOCX
Practica 5
DOCX
Practicas java gustavo carbajal macias 402
DOCX
Ejercicio 5
DOCX
Java problems
PDF
Simulador de sistema de inventario
PPTX
Programa en java con el Metodo de la burbuja
Ejercicios resueltos de programacion
Ejercicios resuletos de programacion
Recuperacion programas
Bucles compuestos ejercicios en código java
Recuperacion programas
Practica 9
Programa 6
Resolución de problemas con java
Cecytem
Manual de prácticas java 2015
colasEjeRe_1_2022.pdf
Ejercicio 5
Ejercicio 5
Ejercicio 5
Practica 5
Practicas java gustavo carbajal macias 402
Ejercicio 5
Java problems
Simulador de sistema de inventario
Programa en java con el Metodo de la burbuja
Publicidad

Último (20)

PDF
Influencia-del-uso-de-redes-sociales.pdf
PDF
Estrategia de Apoyo de Daylin Castaño (5).pdf
PDF
Instrucciones simples, respuestas poderosas. La fórmula del prompt perfecto.
PDF
TRABAJO DE TECNOLOGIA.pdf...........................
PPTX
la-historia-de-la-medicina Edna Silva.pptx
PDF
Tips de Seguridad para evitar clonar sus claves del portal bancario.pdf
PPTX
ANCASH-CRITERIOS DE EVALUACIÓN-FORMA-10-10 (2).pptx
PPTX
El uso de las TIC en la vida cotidiana..
PPTX
Propuesta BKP servidores con Acronis1.pptx
PPT
introduccion a las_web en el 2025_mejoras.ppt
PPTX
sa-cs-82-powerpoint-hardware-y-software_ver_4.pptx
PDF
programa-de-estudios-2011-guc3ada-para-el-maestro-secundarias-tecnicas-tecnol...
PDF
CyberOps Associate - Cisco Networking Academy
PPTX
Presentación PASANTIAS AuditorioOO..pptx
DOCX
Zarate Quispe Alex aldayir aplicaciones de internet .docx
PPTX
Acronis Cyber Protect Cloud para Ciber Proteccion y Ciber Seguridad LATAM - A...
PDF
Ronmy José Cañas Zambrano - Potenciando la tecnología en Venezuela.pdf
PPTX
modulo seguimiento 1 para iniciantes del
PPTX
COMO AYUDAN LAS TIC EN LA EDUCACION SUPERIOR.pptx
PDF
Documental Beyond the Code (Dossier Presentación - 2.0)
Influencia-del-uso-de-redes-sociales.pdf
Estrategia de Apoyo de Daylin Castaño (5).pdf
Instrucciones simples, respuestas poderosas. La fórmula del prompt perfecto.
TRABAJO DE TECNOLOGIA.pdf...........................
la-historia-de-la-medicina Edna Silva.pptx
Tips de Seguridad para evitar clonar sus claves del portal bancario.pdf
ANCASH-CRITERIOS DE EVALUACIÓN-FORMA-10-10 (2).pptx
El uso de las TIC en la vida cotidiana..
Propuesta BKP servidores con Acronis1.pptx
introduccion a las_web en el 2025_mejoras.ppt
sa-cs-82-powerpoint-hardware-y-software_ver_4.pptx
programa-de-estudios-2011-guc3ada-para-el-maestro-secundarias-tecnicas-tecnol...
CyberOps Associate - Cisco Networking Academy
Presentación PASANTIAS AuditorioOO..pptx
Zarate Quispe Alex aldayir aplicaciones de internet .docx
Acronis Cyber Protect Cloud para Ciber Proteccion y Ciber Seguridad LATAM - A...
Ronmy José Cañas Zambrano - Potenciando la tecnología en Venezuela.pdf
modulo seguimiento 1 para iniciantes del
COMO AYUDAN LAS TIC EN LA EDUCACION SUPERIOR.pptx
Documental Beyond the Code (Dossier Presentación - 2.0)

Ejercicios de programacion en java

  • 1. Problema 11: Imprimir un histograma de las edades del curso MA713 el numero de asteriscos corresponde con el número de alumnos de las edades entre 15 y 25 años. 1 package problema11; 2 import java.util.Scanner; 3 4 public class Main 5 { 6 public static void main(String[] args) 7 { 8 9 Scanner s = new Scanner(System.in); 10 int []A = new int[11]; 11 for(int i=0; i<11; i++) 12 A[i]=s.nextInt(); 13 for(int i=0; i<11; i++) 14 { 15 System.out.print(i+15+" "); 16 for(int j=0; j<A[i]; j++) 17 System.out.print("*"); 18 System.out.println(); 19 } 20 } 21 22 } 23 run: 24 0 25 1 26 0 27 2 28 7 29 10 30 12 31 8 32 4 33 2 34 1 35 15 36 16 * 37 17 38 18 ** 39 19 ******* 40 20 ********** 41 21 ************ 42 22 ******** 43 23 **** 44 24 ** 45 25 * 46 GENERACIÓN CORRECTA (total time: 1 minute 8 seconds)
  • 2. Problema 7: Cargar el arreglo A n*m, el arreglo Bm*p. Hallar el producto AxB 1 package problema7; 2 import java.util.Scanner; 3 4 public class Main 5 { 6 public static void main(String[] args) 7 { 8 int m,n,p; 9 Scanner s= new Scanner(System.in); 10 m = s.nextInt(); 11 n = s.nextInt(); 12 p = s.nextInt(); 13 int [][]A = new int [m][n]; 14 int [][]B = new int [n][p]; 15 int [][]C = new int [m][p]; 16 for(int i=0; i<m; i++) 17 for(int j=0; j<n; j++) 18 A[i][j]=s.nextInt(); 19 20 for(int i=0; i<n; i++) 21 for(int j=0; j<p; j++) 22 B[i][j]=s.nextInt(); 23 24 for(int i=0; i<m; i++) 25 for(int j=0; j<p; j++) 26 for(int k=0; k<n; k++) 27 C[i][j]+=A[i][k]*B[k][j]; 28 29 System.out.println("El producto de la matriz AxB es: "); 30 for(int i=0; i<m; i++) 31 { 32 for(int j=0; j<p; j++) 33 System.out.print(C[i][j]+" "); 34 System.out.println(); 35 } 36 } 37 } 38 run: 39 2 1 2 40 3 41 6 42 2 43 4 44 El producto de la matriz AxB es: 45 6 12 46 12 24 47 GENERACIÓN CORRECTA (total time: 8 seconds)
  • 3. Problema 1: Imprimir la lista cargada con números de la serie Fibonacci, método visualizar() 0,1,1,2,3,5… Leer la cantidad de números a sumar, usar método Fibo() 1 package problema1; 2 3 import java.util.Scanner; 4 5 public class Main 6 { 7 public static void main(String[] args) 8 { 9 // TODO code application logic here 10 int n; 11 Scanner Obj = new Scanner(System.in); 12 n = Obj.nextInt(); 13 int []A = new int[100]; 14 A[0]=0; 15 A[1]=1; 16 Fibo(n,A); 17 visualizar(A, n); 18 } 19 20 static void visualizar(int A[], int n){ 21 for(int i=0; i<n-1; i++) 22 System.out.print(A[i]+", "); 23 System.out.println(A[n-1]); 24 } 25 static void Fibo(int n, int A[]) 26 { 27 if(n<2) 28 return; 29 for(int i=2; i<n; i++) 30 A[i]=A[i-1]+A[i-2]; 31 } 32 } 33 run: 34 6 35 0, 1, 1, 2, 3, 5 36 GENERACIÓN CORRECTA (total time: 6 seconds)
  • 4. Problema 2: Determinar la suma y promedio de los n primeros números primos comprendidos entre 1 y 100 1 package problema2; 2 3 import java.util.Scanner; 4 5 public class Main 6 { 7 public static void main(String[] args) 8 { 9 Scanner Obj = new Scanner(System.in); 10 int n = Obj.nextInt(); 11 int A[] = new int[100]; 12 for(int i=2; i<Math.sqrt(100); i++) 13 { 14 int j=i+i; 15 while(j<100) 16 { 17 A[j]=1; 18 j+=i; 19 } 20 } 21 22 int i=0; 23 int j=2; 24 float suma=0; 25 float promedio=0; 26 while(i<n) 27 { 28 if(A[j]==0) 29 { 30 i++; 31 suma+=j; 32 } 33 j++; 34 } 35 promedio=suma/n; 36 System.out.println("La suma de los "+n+" primeros primos es "+suma); 37 System.out.println("El promedio de los "+n+" primeros primos es "+promedio); 38 } 39 } 40 run: 41 5 42 La suma de los 5 primeros primos es 28.0 43 El promedio de los 5 primeros primos es 5.6 44 GENERACIÓN CORRECTA (total time: 4 seconds)
  • 5. 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 package problema3; 2 3 import java.util.Scanner; 4 5 public class Main 6 { 7 public static void main(String[] args) 8 { 9 Scanner Obj = new Scanner(System.in); 10 int n = Obj.nextInt(); 11 int []A = new int [n]; 12 for(int i=0; i<n ; i++) 13 A[i] = Obj.nextInt(); 14 15 int m = Obj.nextInt(); 16 int []B = new int [m]; 17 for(int i=0; i<m ; i++) 18 B[i] = Obj.nextInt(); 19 20 int []C = new int [n+m]; 21 int i=0,j=0; 22 for(int k=0; k<n+m; k++) 23 { 24 if(i>=n) 25 C[k]=B[j++]; 26 else if(j>=m) 27 C[k]=A[i++]; 28 else{ 29 if(A[i]<B[j]) 30 C[k]=A[i++]; 31 else 32 C[k]=B[j++]; 33 } 34 } 35 for(int k=0; k<n+m; k++) 36 System.out.print(C[k]+" "); 37 } 38 } 39 run: 40 4 41 1 2 3 4 42 5 43 5 6 7 8 9 44 1 2 3 4 5 6 7 8 9 GENERACIÓN CORRECTA (total time: 10 seconds)
  • 6. Problema 5: Leer un mensaje y determinar el numero de palabras que tiene, cuantas letras y la palabra de mayor longitud 1 package problema5; 2 import java.util.Scanner; 3 public class Main 4 { 5 public static void main(String[] args) 6 { 7 Scanner Obj = new Scanner(System.in); 8 String msg = Obj.nextLine(); //String []palabras = msg.split(" "); 9 String []palabras = split(msg); 10 11 System.out.println("La frase tiene "+palabras.length+" palabras"); 12 int mayor=palabras[0].length(); 13 for(int i=1; i<palabras.length; i++) 14 if(mayor<palabras[i].length()) 15 mayor=palabras[i].length(); 16 System.out.println("La palabra de mayor longitud tiene "+mayor+" letras"); 17 } 18 static String [] split(String msg){ 19 int n=0; 20 for(int i=0; i<msg.length(); i++){ 21 if(msg.charAt(i)==' ') 22 n++; 23 } 24 String[] words = new String[n+1]; 25 //String[] words = new String[100]; 26 int a=0; 27 int k=0; 28 for(int i=0; i<msg.length(); i++){ 29 if(msg.charAt(i)==' '){ 30 words[k++]=msg.substring(a, i); 31 a=i+1; 32 } 33 } 34 words[k]=msg.substring(a, msg.length()); 35 return words; 36 } 37 } 38 run: 39 Hola como estas 40 La frase tiene 3 palabras 41 La palabra de mayor longitud tiene 5 letras 42 GENERACIÓN CORRECTA (total time: 10 seconds)
  • 7. Problema 6: Leer un arreglo de n números enteros entre 500 y 1500 ordenar de mayor a menor, utilizando el algoritmo de quicksort 1 package problema6; 2 3 import java.util.Scanner; 4 5 public class Main 6 { 7 public static void main(String[] args) 8 { 9 Scanner Obj = new Scanner(System.in); 10 int n = Obj.nextInt(); 11 int []A = new int [n]; 12 for(int i=0; i<n; i++) 13 A[i]=Obj.nextInt(); 14 15 quicksort(A,0,n-1); 16 for(int i=0; i<n; i++) 17 System.out.print(A[i]+" "); 18 } 19 20 static void quicksort(int[] A, int i, int j) { 21 22 if(i==j) 23 return; 24 25 int r=particion(A,i,j); 26 if(i==r )//|| r==i+1) 27 { 28 quicksort(A,r+1,j); 29 } 30 else if(j==r )//|| r==j-1) 31 { 32 quicksort(A,i,r-1); 33 } 34 else 35 { 36 quicksort(A,i,r-1); 37 quicksort(A,r+1,j); 38 } 39 40 41 } 42 static int particion(int []A, int i, int j ){ 43 /*if(i<j) 44 return i;*/ 45 int pivot=A[i]; 46 int r = i;
  • 8. 47 for(int k=i; k<=j; k++) 48 { 49 if(pivot>A[k]) 50 { 51 int temp=A[k]; 52 int t=k; 53 while(t>r) 54 { 55 A[t]=A[t-1]; 56 t--; 57 } 58 r++; 59 A[r-1]=temp; 60 } 61 } 62 return r; 63 } 64 } 65 run: 66 4 67 76 48 94 23 68 23 48 76 94 GENERACIÓN CORRECTA (total time: 11 seconds)
  • 9. Problema 9: leer un mensaje por pantalla y encriptar el mensaje utilizando el código cesar que consiste en hacer un corrimiento de 5 posiciones del carácter alfabetico 1 package problema9; 2 3 import java.util.Scanner; 4 5 public class Main 6 { 7 public static void main(String[] args) 8 { 9 Scanner s = new Scanner(System.in); 10 String msg = s.nextLine(); 11 char []encr = new char[msg.length()]; 12 13 for(int i=0; i<msg.length(); i++) 14 { 15 int tmp = msg.charAt(i); 16 tmp = (tmp - (int) 'a'); 17 tmp = (tmp+5)%26; 18 tmp = tmp + (int)'a'; 19 encr[i]=(char)(tmp); 20 } 21 String nc = new String(encr); 22 System.out.println(encr); 23 } 24 } 25 run: 26 lunes 27 qzsjx 28 GENERACIÓN CORRECTA (total time: 4 seconds)