Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ejercicios;
- import java.util.Scanner;
- /**
- *
- * @author nidroico
- */
- public class Ejercicio_005 {
- public static void main(String[] args) {
- int menor = 0;
- int mayor = 0;
- int a = 0;
- int b = 0;
- int res = 0;
- Scanner sc = new Scanner(System.in);
- boolean repetir = true;
- while (repetir) {
- try {
- System.out.println("Introduce el primer número");
- a = sc.nextInt();
- System.out.println("Introduce el segundo número");
- b = sc.nextInt();
- repetir = false;
- } catch (Exception e) {
- System.out.println("Solo se pueden introducir números");
- System.out.println("Inténtalo de nuevo");
- sc.nextLine();
- }
- }
- if (a == b) {
- System.out.println("Los númros no pueden ser iguales");
- System.out.println("Cerrando el programa en 3,2,1...");
- System.exit(0);
- } else if (a < b) {
- menor = a;
- mayor = b;
- } else {
- mayor = a;
- menor = b;
- }
- int media = (mayor + menor) / 2;
- int escala = 0;
- while (escala < menor) {
- escala++;
- }
- System.out.println("La media entre " + menor + " y " + mayor + " es " + media);
- System.out.print("Lista ascendente desde " + menor + " hasta " + media + " : ");
- do {
- System.out.print(escala + " ");
- escala++;
- } while (escala <= media);
- System.out.println(" ");
- System.out.print("Lista descendente desde " + mayor + " hasta " + media + " : ");
- while (escala < mayor) {
- escala++;
- }
- do {
- System.out.print(escala + " ");
- escala--;
- } while (escala >= media);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement