Struttura iniziale
This commit is contained in:
parent
c326b1ec2f
commit
d9731037f2
@ -20,56 +20,26 @@ public class SequenzaNumeri {
|
||||
static Scanner sc = new Scanner(System.in);
|
||||
public static void main(String[] args) {
|
||||
|
||||
int scelta = -1;
|
||||
do {
|
||||
System.out.println("Scegliere un'opzione:");
|
||||
System.out.println("1. Stampa quadrato pieno");
|
||||
System.out.println("2. Stampa quadrato vuoto");
|
||||
System.out.println("3. Stampa triangolo");
|
||||
System.out.println("4. Stampa quadrato diagonale");
|
||||
System.out.println("0. Esci");
|
||||
System.out.println("Scelta: ");
|
||||
int daLeggere = -1;
|
||||
boolean error;
|
||||
|
||||
try {
|
||||
scelta = sc.nextInt();
|
||||
sc.nextLine();
|
||||
System.out.println("Verrà chiesto di inserire la quantità di numeri da inserire.");
|
||||
Pausa();
|
||||
|
||||
switch (scelta) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
System.out.println(QuadratoPieno(Dimensione(), unit));
|
||||
Pausa();
|
||||
break;
|
||||
case 2:
|
||||
System.out.println(QuadratoVuoto(Dimensione(), unit));
|
||||
Pausa();
|
||||
break;
|
||||
case 3:
|
||||
System.out.println(Triangolo(Dimensione(), unit));
|
||||
Pausa();
|
||||
break;
|
||||
case 4:
|
||||
System.out.println(QuadratoDiagonale(Dimensione(), unit, unit2));
|
||||
Pausa();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
Pausa();
|
||||
break;
|
||||
}
|
||||
do{
|
||||
error = false;
|
||||
daLeggere = InserimentoNumero();
|
||||
|
||||
}
|
||||
catch (InputMismatchException e) {
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
if(daLeggere <= 0){
|
||||
System.out.println("Errore: inserire un numero positivo.");
|
||||
Pausa();
|
||||
error = true;
|
||||
}
|
||||
|
||||
}
|
||||
while (scelta != 0);
|
||||
|
||||
|
||||
|
||||
while (error);
|
||||
|
||||
|
||||
|
||||
}
|
||||
static void Pausa() {
|
||||
System.out.println("Premere un tasto per continuare. . .");
|
||||
@ -78,9 +48,10 @@ public class SequenzaNumeri {
|
||||
|
||||
static int InserimentoNumero() {
|
||||
int ritorno = 0;
|
||||
boolean error = false;
|
||||
boolean error;
|
||||
|
||||
do{
|
||||
do {
|
||||
error = false;
|
||||
System.out.println("Inserire un numero: ");
|
||||
try{
|
||||
ritorno = sc.nextInt();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user