Main, stampe, Pausa e Dimensione
This commit is contained in:
parent
a471157e9a
commit
e65915a5de
@ -4,6 +4,9 @@
|
||||
*/
|
||||
package quadrati_vari;
|
||||
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Verde
|
||||
@ -13,24 +16,26 @@ public class Quadrati_vari {
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
|
||||
static Scanner sc = new Scanner(System.in);
|
||||
public static void main(String[] args) {
|
||||
Console.Clear();
|
||||
|
||||
char unit = '*'; //unità usata per stampare le figure
|
||||
char unit2 = '+'; //unità usata per stampare metà dell'ultima figura
|
||||
|
||||
int scelta = -1;
|
||||
do {
|
||||
Console.WriteLine("Scegliere un'opzione:");
|
||||
Console.WriteLine("1. Stampa quadrato pieno");
|
||||
Console.WriteLine("2. Stampa quadrato vuoto");
|
||||
Console.WriteLine("3. Stampa triangolo");
|
||||
Console.WriteLine("4. Stampa quadrato diagonale");
|
||||
Console.WriteLine("0. Esci");
|
||||
Console.Write("Scelta: ");
|
||||
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: ");
|
||||
|
||||
try {
|
||||
scelta = Convert.ToInt32(Console.ReadLine());
|
||||
scelta = sc.nextInt();
|
||||
sc.nextLine();
|
||||
|
||||
switch (scelta) {
|
||||
case 0:
|
||||
@ -52,14 +57,14 @@ public class Quadrati_vari {
|
||||
Pausa();
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Errore: scelta non valida.");
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
Pausa();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Errore: scelta non valida.");
|
||||
catch (InputMismatchException e) {
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
Pausa();
|
||||
}
|
||||
|
||||
@ -68,29 +73,29 @@ public class Quadrati_vari {
|
||||
}
|
||||
|
||||
static void Pausa() {
|
||||
Console.WriteLine("Premere un tasto per continuare. . .");
|
||||
Console.ReadKey();
|
||||
System.out.println("Premere un tasto per continuare. . .");
|
||||
sc.nextLine();
|
||||
}
|
||||
|
||||
static uint Dimensione() { //restituisce un intero che indica la dimensione di un lato della figura
|
||||
uint ritorno = 0;
|
||||
bool showErrorMessage;
|
||||
static int Dimensione() { //restituisce un intero che indica la dimensione di un lato della figura
|
||||
int ritorno = 0;
|
||||
boolean showErrorMessage;
|
||||
do {
|
||||
showErrorMessage = false;
|
||||
Console.Write("Inserire la dimensione della figura: ");
|
||||
System.out.println("Inserire la dimensione della figura: ");
|
||||
|
||||
try {
|
||||
ritorno = Convert.ToUInt32(Console.ReadLine());
|
||||
if (ritorno == 0) {
|
||||
ritorno = sc.nextInt();
|
||||
if (ritorno <= 0) {
|
||||
showErrorMessage = true;
|
||||
}
|
||||
}
|
||||
catch (Exception) {
|
||||
catch (InputMismatchException e) {
|
||||
showErrorMessage = true;
|
||||
}
|
||||
|
||||
if (showErrorMessage) {
|
||||
Console.WriteLine("Errore: inserire un numero superiore a 0.");
|
||||
System.out.println("Errore: inserire un numero superiore a 0.");
|
||||
}
|
||||
} while (showErrorMessage);
|
||||
return ritorno;
|
||||
@ -102,7 +107,7 @@ public class Quadrati_vari {
|
||||
for (int j = 1; j <= p_dimensione; j++) {
|
||||
Console.Write(p_unit);
|
||||
}
|
||||
Console.WriteLine();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +117,7 @@ public class Quadrati_vari {
|
||||
for (int j = 1; j <= p_dimensione; j++) {
|
||||
Console.Write(p_unit);
|
||||
}
|
||||
Console.WriteLine();
|
||||
System.out.println();
|
||||
}
|
||||
else {
|
||||
for (int j = 0; j <= p_dimensione - 2; j++) {
|
||||
@ -121,7 +126,7 @@ public class Quadrati_vari {
|
||||
}
|
||||
Console.Write(' ');
|
||||
}
|
||||
Console.WriteLine();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,7 +136,7 @@ public class Quadrati_vari {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
Console.Write(p_unit);
|
||||
}
|
||||
Console.WriteLine("");
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +149,7 @@ public class Quadrati_vari {
|
||||
for (int k = (int)p_dimensione - --j; k > 0; k--) {
|
||||
Console.Write(p_unit2);
|
||||
}
|
||||
Console.WriteLine("");
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user