ejercicio 5( (guia)
Dado un valor N, muestre los numeros pares y numeros impares que existen entre 1 y N import java.io.*;
public class ejercicico05 {
public static void main(String[] args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("ingrese el numero");
int n,i;
n=Integer.parseInt(br.readLine());
System.out.println("*los numeros pares son ");
for(i=1; i<=n; i++)
if(i%2==0)
System.out.println(i);
System.out.println("*los numeros impares son ");
for(i=1; i<=n; i++)
if(i%2!=0)
System.out.println(i);
}
}
import java.io.*;
public class SueldoA {
public static void main(String[] args) throws IOException
{BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
double desA, desB, desC,Xsol, SueldoNeto;
System.out.println("ingrese el sueldo";
Xsol=Double.parseDouble(br.readLine());
desA=(0.05)*100;
desB=(0.12)*100;
desC=(0.15)*100;
SueldoNeto=Xsol-(desA+desB+desC);
System.out.println("el descuento por AFP ="+desA);
System.out.println("el descuento por ESSALUD ="+desB);
System.out.println("el descuento por AFP2"+desC);
System.out.println("el sueldo neto es = "+SueldoNeto);
}
}
import java.io.*;
public class Ejercicio03 {
public static void main(String[] args)throws IOException
{BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
int n1, n2,suma,resta,produc,div;
System.out.println("escriba el numero 1"


n1=Integer.parseInt(br.readLine());
System.out.println("escriba el numero 2"


n2=Integer.parseInt(br.readLine());
suma=n1+n2;
resta=n1-n2;
produc=n1*n2;
div=n1/n2;
System.out.println("la suma = "+suma);
System.out.println("la resta = "+resta);
System.out.println("el producto = "+produc);
System.out.println("la division = "+div);
}
}
Condicionales
import java.io.*;
public class jerci01 {
public static void main(String[] args) throws
IOException {BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
double nota;
nota=Double.parseDouble(br.readLine());
if (nota>=10.5)
System.out.println("aprobado");
else
System.out.println("desaprobado");
}
}
otra forma
import java.io.*;
public class jerci01 {
public static void main(String[] args) throws
IOException {BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
System.out.println("ingrese la nota");
double nota;
nota=Double.parseDouble(br.readLine());
if (nota>=0 && nota<10.5)
System.out.println("desaprobado");
else
System.out.println("aprobado");
}
}
import java.io.*;
public class ejerc4 {
public static void main(String[] args) throws IOException
{BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
System.out.println("ingrese los numeros");
int a, b ;
System.out.println("ingrese el numero 1 ");
a=Integer.parseInt(br.readLine());
System.out.println("ingrese el numero 2");
b=Integer.parseInt(br.readLine());
if (a==b)
System.out.println(" estos numeros son iguales");
else if (a>b)
System.out.println(a+" es mayor que " +b);
else
System.out.println(b+ " es mayor que " +a);
}
}
Ejemplo: Ingresar 3 números enteros
positivos e indicar cual es el mayor
import java.io.*;
public class prueba4 {
public static void main(String[] args) throws IOException
{BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int x, y, z;
System.out.println("ingrese el numero 1");
x=Integer.parseInt(br.readLine());
System.out.println("ingrese el numero 2");
y=Integer.parseInt(br.readLine());
System.out.println("ingrese el numero 3");
z=Integer.parseInt(br.readLine());
if (x>y)
if (x>z)
System.out.println("el mayor es "+x );
else
System.out.println("el mayor es "+z);
else
if (y>z)
System.out.println("el mayor es "+y);
else
System.out.println("el maoyor es "+z);
}
}
Ejemplo: Dado un numero, determinar el mes .
import java.io.*;
public class SwitchCase {
public static void main(String[] args)throws IOException
{BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
byte mes;
System.out.println("ingrese el mes del 1 al 12");
mes=Byte.parseByte(br.readLine());
switch (mes)
{ case 1:System.out.println("enero");break;
case 2:System.out.println("febreo");break;
case 3:System.out.println("marzo");break;
case 4:System.out.println("abril");break;
case 5:System.out.println("mayo");break;
case 6:System.out.println("junio");break;
case 7:System.out.println("julio");break;
case 8:System.out.println("agosto");break;
case 9:System.out.println("septiembre");break;
case 10:System.out.println("octubre");break;
case 11:System.out.println("noviembre");break;
case 12:System.out.println("diciembre");break;
default:System.out.println("incorrecto");break;
}
}
}
EJERCICIO Nº2 Escribir un programa que lea N numeros y reporte suma. Plantear la solucion utilzando: While, do While, y for.
codigo:
import java.io.*;
public class Ejercicio03Guia {
/**
* @param args
*/
public static void main(String[] args)throws
IOException{BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
// TODO Auto-generated method stub
System.out.println("ingrese el numero y resione -1 para terminar");
double N;
double suma=0;
do{
N=Double.parseDouble(br.readLine());
if(N<0) break;
suma = suma + N;
}while (true);
System.out.println("sum=" +suma);
}
}
Ejercicio nº4 leer N numeros e indicar cuantos son positivos y negativos
import java.io.*;
public class javas {
public static void main(String[] args)throws IOException
{BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
int n,num,c=0,cp=0,cn=0;
do{
System.out.println("ingrese la cantidad de numeros");
n=Integer.parseInt(br.readLine());
}while(n<=0);
while(c