



Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!




import java.io.*; import java.util.Scanner; public class p1 {static Scanner sc = new Scanner(System.in); static final int max = 100; public static void main(String[] args)throws IOException { int n, may, men; int Edad[] = new int[max]; n = LeerN(); LeerDatos(n, Edad); ReporteDatos(n, Edad); may = CalcularMay(n, Edad); men = CalcularProm(n, Edad); CalcularMen(n, Edad); }^ Reportar(may, men); static int LeerN(){ int n; do{ System.out.println("Ingrese cantidad de datos: "); }while(n <= 0 || n > 100);^ n = sc.nextInt(); }^ return n; static void LeerDatos(int n, int Edad[]){ for(int i = 0; i < n; i++){ do{ System.out.println("Ingrese Edad: "); }while(Edad[i] <= 0);^ Edad[i] = sc.nextInt(); return;^ } } static void ReporteDatos(int n, int Edad[]){ System.out.print("\nReporte de datos: "); for(int i = 0; i < n; i++) { }^ System.out.print(Edad[i]+" "); }^ return; static int CalcularMay(int n, int Edad[]) { int may = 0; System.out.print("\nReporte de mayores: "); for(int i = 0; i < n; i++) { if(Edad[i] >= 18) { System.out.print(Edad[i]+" "); may++; }^ } return may; } static int CalcularMen(int n, int Edad[]) int men = 0; { System.out.print("\nReporte de menores: "); for(int i = 0; i < n; i++) { if(Edad[i] < 18){ System.out.print(Edad[i]+" "); }^ men++; } return men; } static void CalcularProm(int n, int Edad[]){ int se = 0, prom; for(int i = 0; i< n; i++){ se+=Edad[i]; } prom = se / n; return;^ System.out.println("Promedio de edades: "+prom); } static void Reportar(int may, int men){ System.out.println("N° de mayores de edad: "+may); System.out.println("N° de menores de edad: "+men); return; }^ }
import java.io.*; import java.util.Scanner; public class p {static Scanner sc = new Scanner(System.in); static int max = 100; public static void main(String[] args) throws IOException { int n; int[] A = new int[max]; int[] B = new int[max]; int[] C = new int[max]; n = LeerN("\nCantidad de números a ingresar: "); ingresar(n, A, B); suma(n, A, B, C); reportar(n, A, B, C); } static int LeerN(String msj) { int n; do{ System.out.println(msj); n = sc.nextInt(); }while (n <= 0 || n>100); return n; } static void ingresar(int n, int A[], int B[]){ System.out.println("\nIngreso de datos A y B"); for (int i = 0; i < n; i++){ A[i] = LeerN("Ingrese A(" + (i + 1) + "): "); B[i] = LeerN("Ingrese B(" + (i + 1) + "): "); } return; } static void suma(int n, int[] A, int[] B, int C[]){ for(int i = 0; i < n; i++) { C[i] = A[i] + B[i]; } return; } static void reportar(int n, int A[], int B[], int C[]){ System.out.println("\nReporte de C[]"); for(int i = 0; i < n; i++){ System.out.println(A[i] + " + " + B[i] + " = " + C[i]); } return; } }
import java.io.*; import java.util.Scanner; public class p4{ static Scanner sc = new Scanner(System.in); static int MAX = 100 ; public static void main ( String [] args ) throws IOException { int n ; int A [ ] = new int [ MAX ] ; int B [ ] = new int [ MAX ] ; do { n = LeerN ( "Ingresar cantidad de números deseados : ") ; } while (n<=0 || n > 100 ) ; ingreso( n , A) ; reportea(n, A); Calculo( n , A , B) ; reporte( n , A , B ) ; } static int LeerN ( String msj ){ int n ; do { System.out.print( msj ) ; n = sc.nextInt(); } while ( n <= 0 || n>100) ; return n ; } static void ingreso( int n , int A [ ]) { for (int i = 0 ; i < n ; i ++ ) { System.out.print ("Ingresar número para A" + ( i + 1 ) + " : " ); do{ A [i] = sc.nextInt(); }while(A[i]<=0 || A[i]>100); } return ; } static void reportea(int n, int A[]){ System.out.print("\nArreglo a: "); for (int i =0;i<n;i++) { System.out.print(A[i]+" "); } } static void Calculo( int n , int A [ ] , int B [ ]){ int c,n1; for (int i = 0; i < n; i++) { c=0; n1=A[i]; while (n1!=0) { n1 /= 10; c++; } B[i]=c; } return ; } static void reporte( int n , int A [ ] , int B [ ] ) throws IOException { System.out.print("\nArreglo a: "); for (int i =0;i<n;i++) { System.out.print(A[i]+" "); } System.out.print("\nArreglo b: "); for (int i =0;i<n;i++) { System.out.print(B[i]+" "); } } }
import java.io.; import java.util.Scanner; public class p5 { static final int max = 100; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int a[] = new int[max]; int b[] = new int[max]; int p[] = new int[max]; int n; n = leer(); ingresa(n, a, b); reporteab(n, a, b); calcular(n, a, b, p); reporte(n, a, b, p); } static int leer() throws IOException { Scanner sc = new Scanner(System.in); int n; do { System.out.println("Veces a repetir"); n = sc.nextInt(); } while (n <= 0); return n; } static void ingresa(int n, int a[], int b[]) throws IOException { Scanner sc = new Scanner(System.in); for (int i = 0; i < n; i++) { do { System.out.println("Ingresar un número"); a[i] = sc.nextInt(); } while (a[i] <= 0); do { System.out.println("Ingresa un número"); b[i] = sc.nextInt(); } while (b[i] <= 0); } } static void reporteab(int n, int a[], int b[]) throws IOException { System.out.print("\nArreglo A"); for (int i = 0; i < n; i++) { System.out.print(" "+a[i] + " "); } System.out.print("\nArreglo B"); for (int i = 0; i < n; i++) { System.out.print(" "+b[i]+" "); } } static void calcular(int n, int a[], int b[], int p[])throws IOException{ int prod,n1,n2; for (int i=0; i<n; i++) { prod=0; n1=a[i]; n2=b[i]; for (int c=0; c<n2 ; c++) { prod=prod+n1; } p[i]=prod; } } static void reporte(int n, int a[], int b[], int p[]){ System.out.println("\nReporte de los resultado"); for (int i = 0; i < n; i++) { System.out.println(a[i]+"\t\t"+b[i]+"\t=\t"+p[i]); } } }