Download - Ejercicios de programacion concurrente
![Page 1: Ejercicios de programacion concurrente](https://reader037.vdocuments.mx/reader037/viewer/2022100415/557ae2e6d8b42a8f648b52c3/html5/thumbnails/1.jpg)
EJERCICIOS DE PROGRAMACION CONCURRENTE
Ejercicio N1
package funciones;
import java.io.*;
public class CapturaTeclado {
public static void main(String[]args)
throws IOException {
BufferedReader lectura = new BufferedReader(new
InputStreamReader(System.in));
String nombre;
System.out.println("Ingrese su nombre: ");
nombre = lectura.readLine();
System.out.println("Bienvenido "+nombre);
int num1,num2,num3;
System.out.println("Ingrese numero 1: ");
num1 = Integer.parseInt(lectura.readLine());
System.out.println("Ingrese numero 2: ");
num2 = Integer.parseInt(lectura.readLine());
num3=num1+num2;
System.out.println("La suma de "+num1+" + "+num2 + "numero es
"+num3);
}
}
Ejercicio N2
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package funciones;
import java.io.*;
/**
*
* @author Aunar 11
*/
public class Clases {
public static void main(String[] args) throws IOException{
/** La entrada de datos en Java se efectúa mediante
* la lectura de bytes, la entrada básica de suele
* realizarse mediante el método readLine ()
* que pertenece a la clase BufferedReader,
* el cual se encarga de leer una secuencia
![Page 2: Ejercicios de programacion concurrente](https://reader037.vdocuments.mx/reader037/viewer/2022100415/557ae2e6d8b42a8f648b52c3/html5/thumbnails/2.jpg)
* de caracteres y devuelve una cadena. Para
* esto se debe construir un objeto de la clase
* BufferedReader sobre otro de la clase
* InputStreamReader el cual debe de estar
* asociado a System.in, mismo que se va a
* encargar de convertir a cadena los bytes
* leÃdos desde el teclado.
*/
BufferedReader lectura = new BufferedReader(new
InputStreamReader(System.in));
try {
int num1=0, num2=0, num3=0;
restaPorReferencia OperacionResta = new restaPorReferencia();
System.out.println("Ingrese numero 1: ");
num1 = Integer.parseInt(lectura.readLine());
System.out.println("Ingrese numero 2: ");
num2 = Integer.parseInt(lectura.readLine());
OperacionResta.restaPorReferencia(num1,num2);
restaPorValor OperacResta = new restaPorValor();
System.out.println("Ingrese numero 1: ");
num1 = Integer.parseInt(lectura.readLine());
System.out.println("Ingrese numero 2: ");
num2 = Integer.parseInt(lectura.readLine());
num3= OperacResta.restaPorValor(num1,num2);
System.out.println("El valor de la resta de por valor de " +
num1 + " - "+ num2 + " es: " + num3);
}
catch(NumberFormatException ex){
System.out.println("Ocurrio algun error en: " + ex);
}
}
static class restaPorReferencia
{
void restaPorReferencia(int a, int b) {
int res;
res= a- b;
System.out.println("El valor de la resta por referencia de
" + a + " - "+ b + " es: " + res);
![Page 3: Ejercicios de programacion concurrente](https://reader037.vdocuments.mx/reader037/viewer/2022100415/557ae2e6d8b42a8f648b52c3/html5/thumbnails/3.jpg)
}
}
static class restaPorValor
{
int restaPorValor(int n1, int n2){
int p;
p=n1-n2;
return(p);
}
}
}
Ejercicio N3
package funciones;
public class FuncionesPorValorYPorReferencia {
public static void main(String[] args) {
// TODO code application logic here
int num1=20, num2=15, num3=0,num4=60,num5=20;
restaPorReferencia(num1,num2);
num3= RestaPorValor(num4,num5);
System.out.println("El valor de la resta de por valor de " +
num4 + " - "+ num5 + " es: " + num3);
}
static void restaPorReferencia(int a, int b) {
int res;
res= a- b;
System.out.println("El valor de la resta por referencia de " +
a + " - "+ b + " es: " + res);
}
static int RestaPorValor(int n1, int n2){
int p;
p=n1-n2;
return(p);
}
}
Ejercicio N4
/*
![Page 4: Ejercicios de programacion concurrente](https://reader037.vdocuments.mx/reader037/viewer/2022100415/557ae2e6d8b42a8f648b52c3/html5/thumbnails/4.jpg)
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package funciones;
/**
*
* @author Aunar 11
*/
public class Try_Catch {
public static void main(String args[]){
int numero;
String cadena=" 1";
try{
numero = Integer.parseInt(cadena);
}
catch(NumberFormatException ex){
System.out.println("No es un número, es una cadena de texto.");
}
}
}
Edgar Leandro Munoz Quenan
Tec.Sistemas