Java - ¿Cómo hago para volver al Menú principal?

 
Vista:

¿Cómo hago para volver al Menú principal?

Publicado por Bryan Cy (3 intervenciones) el 07/05/2019 03:38:12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package calculadora;
 
import java.util.Scanner;
 
public class Calculadora {
    public static void main(String[] args) {
 
    Scanner x = new Scanner(System.in);
    int num, contador, op;
    double num1, num2, res;
    char centinela;
 
    System.out.println("1. SUMA DE DOS NÚMEROS");
    System.out.println("2. RESTA DE DOS NÚMEROS");
    System.out.println("3. MULTIPLICACIÓN DE DOS NÚMEROS");
    System.out.println("4. DIVISIÓN DE DOS NÚMEROS");
    System.out.println("5. SALIR");
    System.out.print("INGRESA UNA OPCIÓN: ");
    num=x.nextInt();
    switch (num)
    {
        case 1:
            contador=0;
            centinela='S' & 's';
            while(centinela != 'n' && centinela != 'N')
            {
                System.out.println("SUMA");
                System.out.print("INGRESE EL PRIMER NÚMERO: ");
                num1=x.nextDouble();
                System.out.print("INGRESE EL SEGUNDO NÚMERO: ");
                num2=x.nextDouble();
                res=num1+num2;
                System.out.println("LA SUMA ES: "+res);
                System.out.print("DESEA CONTINUAR S/N : ");
                centinela=x.next().charAt(0);
                contador++;
             }
             break;
 
        case 2:
            contador=0;
            centinela='S' & 's';
            while(centinela != 'n' && centinela != 'N')
            {
                System.out.println("RESTA");
                System.out.print("INGRESE EL PRIMER NÚMERO: ");
                num1=x.nextDouble();
                System.out.print("INGRESE EL SEGUNDO NÚMERO: ");
                num2=x.nextDouble();
                res=num1-num2;
                System.out.println("LA RESTA ES: "+res);
		System.out.print("DESEA CONTINUAR S/N :");
		centinela=x.next().charAt(0);
		contador++;
            }
            break;
        case 3:
            contador=0;
            centinela='S' & 's';
            while(centinela != 'n' && centinela != 'N')
            {
                System.out.println("MULTIPLICACIÓN");
                System.out.print("INGRESE EL PRIMER NÚMERO: ");
                num1=x.nextDouble();
                System.out.print("INGRESE EL SEGUNDO NÚMERO: ");
                num2=x.nextDouble();
                res=num1*num2;
                System.out.println("LA MULTIPLICACIÓN ES: "+res);
		System.out.print("DESEA CONTINUAR S/N :");
		centinela=x.next().charAt(0);
		contador++;
            }
            break;
        case 4:
            contador=0;
            centinela='S' & 's';
            while(centinela != 'n' && centinela != 'N')
            {
                System.out.println("DIVISIÓN");
                System.out.print("INGRESE EL PRIMER NÚMERO: ");
                num1=x.nextDouble();
                System.out.print("INGRESE EL SEGUNDO NÚMERO: ");
                num2=x.nextDouble();
                res=num1/num2;
                System.out.println("LA DIVISIÓN ES: "+res);
		System.out.print("DESEA CONTINUAR S/N :");
		centinela=x.next().charAt(0);
		contador++;
            }
            break;
        case 5:
            System.exit(0);
 
        default:
            System.out.println("Solo números entre 1 y 5");
        }
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Rodrigo
Val: 2.041
Plata
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

¿Cómo hago para volver al Menú principal?

Publicado por Rodrigo (623 intervenciones) el 07/05/2019 06:20:13
Encierra toda la logica al interior de un ciclo while.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar