Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
JAVA
201
0
TRABAJO ENCARGADO
RESUELVA LOS SIGUIENTES EJERCICIOS EN JAVA
1. Se tiene la informacin de ingresos econmicos quincenales de 10 familias, las
cuales son las siguientes: [150, 200, 180, 160, 154, 160, 200, 210, 160, 155].
Almacene dichos valores en un array unidimensional y calcule la suma total de los
ingresos.
import javax.swing.JOptionPane;
public class Ejemplo3{
public static void main(String args[]){
int[] matriz=new int[10];
String cad;
int suma=0;
int i;
for( i=0;i<10;i++){
cad=JOptionPane.showInputDialog("ingre un dato de la matriz");
matriz[i]=Integer.parseInt(cad);
}
for( i=0;i<10;i++){
suma=suma+matriz[i];
}
}
JOptionPane.showMessageDialog("la suma es :"+suma);
}
Pg.1
}
}
3. Realice un programa que permita almacenar los nombres de n personas con sus
respectivas estaturas (expresado en metros). Dichos valores debern de
visualizarse; adems deber visualizar las personas que tienen estaturas mayores
iguales a 1.75mts.
4. Utilizando arrays bidimensionales represente la siguiente matriz:
12 20 19
Datos= 10 3 17
8
26 12
import java.util.Scanner;
public class Ejemplo4 {
private Scanner teclado;
private int[][] mat;
public void cargar() {
teclado=new Scanner(System.in);
mat=new int[3][3];
for(int f=0;f<3;f++) {
for(int c=0;c<3;c++) {
System.out.print("Ingrese numero:");
mat[f][c]=teclado.nextInt();
}
}
}
public void imprimir() {
for(int f=0;f<3;f++) {
for(int c=0;c<3;c++) {
System.out.print(mat[f][c]+" ");
}
System.out.println();
}
}
public static void main(String[] ar) {
Ejemplo4 ma=new Ejemplo4();
ma.cargar();
ma.imprimir();
}
}
Luis Alberto Coyla Torres
Pg.2
5. Realice un programa donde se ingrese los valores de una matriz de orden (m=filas
y n=columnas). Dichos valores sern ingresados desde teclado y deber controlar
los posibles errores.
201
0
import java.io.*;
class Ejemplo5{
public static void main(String args[])throws IOException{
Buff eredReader EN=new Buff eredReader(new
InputStreamReader(System.in));
int mat[][]=new int[10][10];
int M,N;
System.out.println("inserte la cantidad de fi las");
M=Integer.parseInt(EN.readLine());
System.out.println("inserte la cantidad de columnas");
N=Integer.parseInt(EN.readLine());
System.out.println("inserte los datos");
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
mat[i][j]=Integer.parseInt(EN.readLine());
for(int i=0;i<M;i++){
for(int j=0;j<N;j++)
System.out.print(mat[i][j]+" ");
System.out.println();
}
}
}
1
5
1
5
1
1
1
6
-5
1
2
1
5
1
3
1
5
1
2
1
5
1
5
2
0
-9
1
0
1
1
1
6
1
0
1
4
1
4
-5
2
0
1
1
1
7
-2
1
0
-5
1
2
1
5
1
3
1
5
1
2
1
5
1
5
1
3
1
5
2
0
-9
1
0
1
1
1
6
2
0
-9
1
0
1
0
1
4
1
4
-5
1
0
1
4
1
4
2
0
1
1
1
7
2
0
1
1
1
7
-2
1
0
-5
-2
1
0
-5
Pg.3
1
2
1
5
201
0
C1
C2
C3
Pg.4
201
0
break;
}
}
[ ]
12 10
[ 23 45 56 ] 11 36 =[ 1611 2970 ]
15 20
import java.util.*;
public class Ejemplo3{
public static void main (String[]Args){
int matriza[][] = new int [1][3];
int matrizb[][] = new int [3][2];
int matrizc[][] = new int [1][2];
int i, j;
Scanner dato = new Scanner (System.in);
System.out.println("Datos de la Matriz A :");
for (i=0; i<=2; i++){
for (j=0; j<=2; j++){
System.out.print("Escribir valor " + i + " , " + j + " : ");
matriza [i][j]= dato.nextInt();
}
}
System.out.println("Datos de la Matriz B:");
for (i=0; i<=2; i++){
for (j=0; j<=2; j++){
System.out.print("Escribir valor " + i + " , " + j + " : ");
matrizb [i][j]= dato.nextInt();
}
}
for (i=0; i<=2; i++){
for (j=0; j<=2; j++){
matrizc [i][j]= matriza[i][j]*matrizb[i][j];
}
}
System.out.println("Matriz resultante de la multiplicacin :");
for (i=0;i<=2;i++){
Luis Alberto Coyla Torres
Pg.5
for (j=0;j<=2;j++) {
System.out.print(matrizc[i][j] + " ");
}
System.out.println("");
201
0
}
}
}
Pg.6