Documentos de Académico
Documentos de Profesional
Documentos de Cultura
((750308))
En total, ¿cuántos son los valores numéricos reales que pueden ser almacenados entre todas
las siguientes variables?
?
1 double variableA[] = new double[11];
2 Scanner varaibleB[];
3 double variableC[][] = new double[3][3];
11,0,3
Importante: Ud. solo debe ingresar dentro de la casilla un único valor numérico.
Falso
Verdadero
Arrays – arreglos
Exception – arreglos
Throwable – arreglos
Arrays – registros
numérico
por referencia
primitivo
clase
En donde:
if (temperatura[i][0] == 9 AND
temperatura[i][1] == 9)
if (temperatura[i][0] == 9 OR
temperatura[i][1] == 9)
if (temperatura[i][0] == 9 &&
temperatura[i][1] == 9)
if (temperatura[i][0] == 9 ||
temperatura[i][1] == 9)
Dado el siguiente flujo de código, ubicarse en la línea de código nro. 6 (bloque vacío try) y
evaluar cual es la Excepción que se Captura dentro de cada catch si se lanza (explicita o
implícitamente) cada una de las excepciones listadas.
?
1
2 public static void main(String[] args) {
3 Scanner teclado = new Scanner(System.in);
int valor1, valor2 = 0, resultado;
4 int arr[] = new int[2];
5 try {
6
7 } catch (InputMismatchException inputMismatchException) {
8 System.err.println("Error de inputMismatchException");
} catch (ArithmeticException arithmeticException) {
9
System.err.println("Error de arithmeticException");
10 } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
11 System.err.println("Error de arrayIndexOutOfBoundsException");
12 } catch (IOException ioException) {
13 System.err.println("Error de ioException");
} catch (Exception exception) {
14 System.err.println("Error de exception");
15 }
16 }
17
18
EXCEPCIONES CAPTURADAS
1. inputMismatchException
2. arithmeticException
3. arrayIndexOutOfBoundsException
4. ioException
5. exception
EXCEPCIONES LANZADAS
v. Scanner fileTest = new Scanner(new File("FileTest.txt"));
w. arr[2] = 9;
x. resultado = valor1 / valor2;
y. valor1 = teclado.nextInt();
z. throw new RuntimeException();
Dado el siguiente flujo, la excepción lanzada debido a la condición i <= notas.length (línea
15) es:
?
1 public static void main(String[] args) {
2 int notas[] = new int[2];
try {
3 ingresoDatos(notas);
4 } catch (ArrayIndexOutOfBoundsException e1) {
5 System.out.println("Arreglo fuera de rango");
6 } catch (Exception e2) {
7 System.out.println(e2.getMessage());
}
8 }
9
10 public static void ingresoDatos(int notas[])
11 throws ArrayIndexOutOfBoundsException {
12 Scanner entrada = new Scanner(System.in);
for (int i = 0; i <= notas.length; i++) {
13 notas[i] = entrada.nextInt();
14 }
15 }
16
17
18
InputMismatchException
ArithmeticException
ArrayIndexOutOfBoundsException
Exception
Dado el siguiente flujo de código, indicar cual es la afirmación que se cumple al respecto de
las buenas y malas prácticas en el manejo de excepciones:
?
1
2 Scanner teclado = new Scanner(System.in);
double respt, num1, num2;
3 num1 = teclado.nextDouble();
4 num2 = teclado.nextDouble();
5 try {
6 respt = num1 / num2;
} catch (ArithmeticException arithmeticException) {
7 } catch (Exception exception) {
8 }
9
Una excepción no atrapada ocurre cuando no hay bloques catch que coincidan.
Dado el siguiente código, ¿cuáles son los conceptos que se aplica a dicho escenario/flujo.?
?
1
try {
2 int respt = 0, a =3, b=0;
3 respt = b!=0 ? a/b: 0;
4 respt = a / b;
5 } catch (Exception e) {
System.out.println(e.getMessage());
6 }
7
Importante: Ud. debe elegir más de una alternativa como respuesta correcta.
Genera repeticiones.
Impide excepciones.
Previene excepciones.
Lanza excepciones.
Maneja excepciones.
Exception – verificadas
IOException – no verificadas
RuntimeException – no verificadas
RuntimeException – verificadas
?
1
public static void main(String[] args) {
2 System.out.println(recursivoA(3));
3 }
4
5 public static int recursivoA(int valor) {
6 if (valor == 1)
7 return valor + 2;
return recursivoA(valor - 1);
8 }
9
int[] vector =
{1,4,7,8,9,14,23,47,56,60,61,63,65,66,68};
arreglo.length() / 3;
arreglo.length() – 1;
arreglo.length()
La instrucción for mejorado permite a los programadores iterar a través de los elementos de
un arreglo o de una colección, sin utilizar un contador. La sintaxis de una instrucción for
mejorado es:
?
1 for ( parametro : nombreArreglo )
2 {
3 instrucciones
4 }
El tipo de dato declarado en parametro debe ser _______ los valores almacenados en el
arreglo nombreArreglo.
long como
String como
diferente a
variable
métodos
clases
arreglos
retorno – genera
Dado el siguiente flujo, ¿Cuál es la variable que ocasiona el desbordamiento de notas[ ] y por
ende la excepción ArrayIndexOutOfBoundsException?.
?
1
2 public static void ingresoDatos(int notas[])
throws ArrayIndexOutOfBoundsException {
3 Scanner entrada = new Scanner(System.in);
4 int suma = 0, promedio = 0;
5 for (int i = 0; i <= notas.length; i++) {
6 notas[i] = entrada.nextInt();
7 suma+=notas[i];
}
8 promedio=suma/notas.length;
9 }
10
Promedio
IOException
MiException4
Exception
MiException1
MiException2
MiException3
RuntimeException
?
1 try {
2 int respt = 3/0;
3 } catch (Exception e) {
4 System.out.println("Exception");
5 }
?
1 try {
2 int arreglo1[] = {3, 2, 1};
3 System.out.println(arreglo1[3]);
4 } catch (Exception e) {
5 System.out.println("Exception");
6 }
?
1 try {
2 int arreglo2[] = {3, 2, 1};
3 for(char array : arreglo2)
4 System.out.println(array);
5 } catch (Exception e) {
6 System.out.println("Exception");
7 }
?
1 try {
2 throw new Exception();
3 } catch (Exception e) {
4 System.out.println("Exception");
5 }
Solución a la pregunta número 24
Conexiones a Bases.
?
1 int numeros[] = {-2, 4, 10}, sum = -1;
2 for (int num : numeros) {
3 sum -= num;
4 }
System.out.println(sum);
5
11
Selección
Lineal
Inserción
Burbuja
Burbuja mejorado
Binario
Verdadero
Falso
Verdadero