Sembra funzionare tutto
This commit is contained in:
parent
26c84d3f57
commit
c1d961ae36
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package stringhe1;
|
package stringhe1;
|
||||||
|
|
||||||
import java.util.InputMismatchException;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,46 +19,40 @@ public class stringhe1 {
|
|||||||
static Scanner sc = new Scanner(System.in);
|
static Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int scelta = -1;
|
int numeroRighe = 0, numeroCaratteri = 0, numeroAlfanumerici = 0, numeroParole = 0, indiceRiga = 0;
|
||||||
|
final int LUNGHEZZA_RIGA = 100;
|
||||||
|
final int NUMERO_RIGHE = 1000;
|
||||||
|
String riga, uscita = "FINE";
|
||||||
|
char testo[][] = new char[NUMERO_RIGHE][LUNGHEZZA_RIGA];
|
||||||
|
boolean exit = false;
|
||||||
do {
|
do {
|
||||||
System.out.println("Scegliere un'opzione:");
|
do {
|
||||||
System.out.println("1. ");
|
System.out.println("Inserire il testo (inserire 'FINE' per terminare):");
|
||||||
System.out.println("2. ");
|
riga = sc.nextLine();
|
||||||
System.out.println("3. ");
|
if (riga.length() > LUNGHEZZA_RIGA) {
|
||||||
System.out.println("0. Esci");
|
System.out.println("La riga supera i " + LUNGHEZZA_RIGA + " caratteri. Riprovare.");
|
||||||
System.out.print("Opzione: ");
|
|
||||||
|
|
||||||
try {
|
|
||||||
scelta = sc.nextInt();
|
|
||||||
sc.nextLine();
|
|
||||||
|
|
||||||
switch (scelta) {
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
|
|
||||||
Pausa();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
|
|
||||||
Pausa();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
|
|
||||||
Pausa();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.out.println("Opzione non valida.");
|
|
||||||
Pausa();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InputMismatchException e) {
|
|
||||||
System.out.println("Errore: scelta non valida.");
|
|
||||||
Pausa();
|
Pausa();
|
||||||
}
|
}
|
||||||
} while (scelta != 0);
|
} while (riga.length() > LUNGHEZZA_RIGA);
|
||||||
|
|
||||||
|
if (!riga.equals(uscita)) {
|
||||||
|
testo[indiceRiga] = riga.toCharArray();
|
||||||
|
numeroRighe++;
|
||||||
|
numeroCaratteri += testo[indiceRiga].length;
|
||||||
|
numeroAlfanumerici += riga.split("[A-Za-z1-9]").length;
|
||||||
|
numeroParole += riga.split("\\s").length;
|
||||||
|
indiceRiga++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Numero totale di righe inserite: " + numeroRighe);
|
||||||
|
System.out.println("Numero totale di caratteri inseriti: " + numeroCaratteri);
|
||||||
|
System.out.println("Numero totale di caratteri alfanumerici inseriti: " + numeroAlfanumerici);
|
||||||
|
System.out.println("Numero totale di parole inserite: " + numeroParole);
|
||||||
|
Pausa();
|
||||||
|
exit = true;
|
||||||
|
}
|
||||||
|
} while (numeroRighe <= NUMERO_RIGHE && !exit);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Pausa() {
|
public static void Pausa() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user