0% encontró este documento útil (0 votos)
41 vistas

Programas Condicionales

El documento presenta 11 ejercicios de programación condicionales en Java, donde se piden valores de entrada y se evalúan condiciones para imprimir mensajes u obtener resultados diferentes.

Cargado por

Jose
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
41 vistas

Programas Condicionales

El documento presenta 11 ejercicios de programación condicionales en Java, donde se piden valores de entrada y se evalúan condiciones para imprimir mensajes u obtener resultados diferentes.

Cargado por

Jose
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 13

Programas Ejercicios condicionales

Katherin Yaneth Salinas Velasquez

Ejercicio 1
import java.util.*;

public class numopuestos {//Inicio


public static void main(String[] args) {
Scanner m = new Scanner(System.in);
int x, y;

System.out.println("Ingrese el primer numero: ");


x = m.nextInt();

System.out.println("Ingrese el segundo numero: ");


y = m.nextInt();

if ((x > 0 && y < 0) || (x < 0 && y > 0)) {


System.out.println("Los numeros " + x + " , " + y
+ " son de signos opuestos.");
}
else {
System.out.println("Los numeros son de igual
signo.");
}
}
}//Fin

Ejercicio 2
import java.util.*;

public class nummayor


{//Inicio
public static void main(String[] args) {
Scanner b = new Scanner(System.in);
double d, c, s, r, p, i;

System.out.println("Ingrese el primer numero: ");


d = b.nextDouble();
System.out.println("Ingrese el segundo numero: ");
c = b.nextDouble();

if (d > c) {
s = d + c;
r = d - c;
System.out.println("La suma de los numeros es: "
+ s + " y la diferencia es: " + r);
} else if (c > d) {
p = d * c;
if (c != 0) {
i = d / c;
System.out.println("El producto de los
numeros es: " + p + " y la division es: " + i);
} else {
System.out.println("La division no se puede,
el segundo numero es cero.");
}
} else {
System.out.println("Los numeros son iguales.");
}
}
}//Fin

Ejercicio 3
import java.util.*;
public class dosdigitos
{//Inicio
public static void main(String[] args)
{

Scanner s=new Scanner(System.in);


int x;

System.out.println("Ingrese el numero: ");


x=s.nextInt();
if (x >= 1 && x <= 9){
System.out.println("El numero tiene un solo
digito.");
}
if (x >= 10 && x <= 99){
System.out.println("El numero tiene dos digitos.");
}

else{
System.out.println("El numero no esta en el rango.");
}

}//Fin

Ejercicio 4
import java.util.*;
public class supermercado
{//Inicio
public static void main(String[] args)
{

Scanner u=new Scanner(System.in);


double x,y,z,w,o;

System.out.println("Ingrese la cantidad unitaria del


producto a llevar: ");
x=u.nextDouble();

System.out.println("Ingrese la cantidad total: ");


y=u.nextDouble();

if(x >= 36) {


z=y-(y*0.15);
o=x+1;
System.out.println("Tu total es de: "+z+" y te llevas:
"+o+" productos.");
}
else {
w=y-(y*0.10);
System.out.println("Su total es de "+w+" Lempiras.");
}

}//Fin
Ejercicio 5
import java.util.*;
public class numalreves
{//Inicio
public static void main(String[] args)
{
Scanner h=new Scanner(System.in);
int x,pd,sd,td,i;

System.out.println("Ingrese el numero: ");


x=h.nextInt();

if(x >= 100 && x <= 999){


td = x % 10;
sd = (x / 10) % 10;
pd = (x / 100) % 10;
i= td*100+sd*10+pd;
System.out.println("El numero al reves es: "+i);
if(x == i){
System.out.println("Los numeros "+x+" y "+i+" son el mismo
numero.");
}
}

}//Fin

Ejercicio 6
import java.util.*;
public class descendente
{//Inicio
public static void main(String[] args)
{
Scanner r=new Scanner(System.in);
int x,y,z;

System.out.println("Ingrese el primer numero: ");


x=r.nextInt();
System.out.println("Ingrese el segundo numero: ");
y=r.nextInt();

System.out.println("Ingrese el tercer numero: ");


z=r.nextInt();

if(x >= y && x >= z){


if(y >= z)
System.out.println("Los numeros en forma descendente
son: "+x+" ,"+y+" y "+z);
else
System.out.println("Los numeros en forma descendente
son: "+x+" ,"+z+" y "+y);
}
else if(y >= x && y >= z){
if(x >= z)
System.out.println("Los numeros en forma descendente
son: "+y+" ,"+x+" y "+z);
else
System.out.println("Los numeros en forma descendente
son: "+y+" ,"+z+" y "+x);
}
else{
if(x >= y)
System.out.println("Los numeros en forma descendente
son: "+z+" ,"+x+" y "+y);
else
System.out.println("Los numeros en forma descendente
son: "+z+" ,"+y+" y "+x);
}

}//Fin
Ejercicio 7
import java.util.*;

public class Alquilervehiculo


{//Inicio
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Constantes
final double ISV = 0.15;
final double MF = 600.00;
final int LKM1 = 300;
final int LKM2 = 1000;
final double MAKM1 = 12.00;
final double MAKM2 = 20.00;

// Leer la cantidad de kilómetros recorridos


System.out.print("Ingrese la cantidad de kilómetros
recorridos: ");
int kmRecorridos = scanner.nextInt();

// Calcular el monto a pagar por el alquiler del


vehículo
double montoAlquiler;
double montoImpuesto;

if (kmRecorridos <= LKM1) {


montoAlquiler = MF;
} else if (kmRecorridos <= LKM2) {
montoAlquiler = MF + (kmRecorridos - LKM1) *
MAKM1;
} else {
montoAlquiler = MF + (LKM2 - LKM1) * MAKM1
+ (kmRecorridos - LKM2) * MAKM2;
}

// Calcular el monto del impuesto sobre ventas


montoImpuesto = montoAlquiler * ISV;

// Calcular el monto total a pagar (monto alquiler +


monto impuesto)
double montoTotal = montoAlquiler + montoImpuesto;

// Mostrar resultados
System.out.println("Monto a pagar por el alquiler del
vehículo: L. " + montoAlquiler);
System.out.println("Monto incluido del impuesto sobre
ventas: L. " + montoImpuesto);
System.out.println("Monto total a pagar: L. " +
montoTotal);

scanner.close();
}
}//Fin
Ejercicio 8
import java.util.*;

public class promediopracticas


{//Inicio

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

// if1
double[] notas = new double[4];
System.out.println("Ingrese las 4 notas de
prácticas:");
for (int i = 0; i < 4; i++) {
System.out.print("Nota " + (i + 1) + ": ");
notas[i] = scanner.nextDouble();
}

// if2
Arrays.sort(notas);

// if3
double promedio = (notas[1] + notas[2] + notas[3]) /
3;

// if4
System.out.println("La nota a eliminar es: " +
notas[0]);
System.out.println("El promedio de prácticas es: " +
promedio);
}
}//Fin
Ejercicio 9
import java.util.*;

public class tipotriangulo


{

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
//
System.out.println("Ingrese la longitud del lado 1
del triángulo:");
double l1 = scanner.nextDouble();
System.out.println("Ingrese la longitud del lado 2
del triángulo:");
double l2 = scanner.nextDouble();
System.out.println("Ingrese la longitud del lado 3
del triángulo:");
double l3 = scanner.nextDouble();

if (esTriangulo(l1, l2, l3))


{
String tipoTriangulo =
determinarTipoTriangulo(l1, l2, l3);
System.out.println("Las longitudes ingresadas
forman un triángulo de tipo " + tipoTriangulo);
} else {
System.out.println("Las longitudes ingresadas no
forman un triángulo");
}
}

public static boolean esTriangulo(double l1, double l2,


double l3) {
return l1 + l2 > l3 && l1 + l3 > l2 && l2 + l3 > l1;
}

public static String determinarTipoTriangulo(double l1,


double l2, double l3) {
if (l1 == l2 && l2 == l3) {
return "Equilátero";
} else if (l1 == l2 || l1 == l3 || l2 == l3) {
return "Isósceles";
} else {
return "Escaleno";
}
}
}//Fin
Ejercicio 10
import java.util.*;

public class numeromayor


{//Inicio

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.println("Ingrese un número entero de tres


cifras:");
int numero = scanner.nextInt();

if (numero >= 100 && numero <= 999) {


int mayorNumero = formarMayorNumero(numero);
System.out.println("El mayor número formado es: "
+ mayorNumero);
} else {
System.out.println("El número ingresado no tiene
tres cifras.");
}
}

public static int formarMayorNumero(int numero) {


int c1 = numero / 100;
int c2 = (numero / 10) % 10;
int c3 = numero % 10;

if (c1 < c2) {


int temp = c1;
c1 = c2;
c2 = temp;
}
if (c1 < c3) {
int temp = c1;
c1 = c3;
c3 = temp;
}
if (c2 < c3) {
int temp = c2;
c2 = c3;
c3 = temp;
}
int mayorNumero = c1 * 100 + c2 * 10 + c3;
return mayorNumero;
}
}//Fin
Ejercicio 11
public class mesdelanio
{//Inicio

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.println("Ingrese un número entre 1 y


12:");
int numero = scanner.nextInt();

if (numero >= 1 && numero <= 12) {


String mes = obtenerNombreMes(numero);
System.out.println("El número " + numero + "
corresponde al mes de " + mes + ".");
} else {
System.out.println("El número ingresado no está
dentro del rango válido.");
}
}

public static String obtenerNombreMes(int numero) {


String[] meses = {
"enero", "febrero", "marzo", "abril", "mayo",
"junio",
"julio", "agosto", "septiembre", "octubre",
"noviembre", "diciembre"
};
return meses[numero - 1];
}
}//Fin

Ejercicio 12
import java.util.*;

public class Suma


{//Inicio
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Ingrese el primer número:");


int n1 = scanner.nextInt();
System.out.println("Ingrese el segundo número:");
int n2 = scanner.nextInt();
System.out.println("Ingrese el tercer número:");
int n3 = scanner.nextInt();

if ((n1 + n2 == n3) || (n1 + n3 == n2) || (n2 + n3 ==


n1)) {
System.out.println("iguales");
} else {
System.out.println("distintas");
}
}
}//Fin
Ejercicio 13
import java.util.*;

public class salario


{//Inicio

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.println("Ingrese las horas trabajadas:");


int ht = scanner.nextInt();
System.out.println("Ingrese el sueldo por hora:");
double sph = scanner.nextDouble();

double sb;
if (ht <= 35) {
sb = ht * sph ;
} else {
sb = (35 * sph) + ((ht - 35) * (1.5 * sph));
}

double ip;
double sn;
if (sb <= 2500.00) {
ip = 0.00;
sn = sb;
} else {
ip = 0.12 * sb;
sn = sb - ip;
}

// Mostrar el salario bruto, los impuestos y el


salario neto
System.out.println("Salario Bruto: L." + sb);
System.out.println("Impuestos: L." + ip);
System.out.println("Salario Neto: L." + sn);
}
}//Fin

Ejercicio 14
public class ecuaciones
{//Inicio

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.println("Ingrese el coeficiente a:");


double a = scanner.nextDouble();
System.out.println("Ingrese el coeficiente b:");
double b = scanner.nextDouble();
System.out.println("Ingrese el coeficiente c:");
double c = scanner.nextDouble();
System.out.println("Ingrese el coeficiente d:");
double d = scanner.nextDouble();
System.out.println("Ingrese el coeficiente e:");
double e = scanner.nextDouble();
System.out.println("Ingrese el coeficiente f:");
double f = scanner.nextDouble();

double dn = (a * e - b * d);
double x = (c * e - b * f) / dn;
double y = (a * f - c * d) / dn;

System.out.println("El valor de x es: " + x);


System.out.println("El valor de y es: " + y);
}
}//Fin

También podría gustarte