Fix and delate nextLine()

This commit is contained in:
Orange_Dugongo 2016-10-21 14:41:53 +02:00
parent 3f0a55026c
commit a8e5494aa0
6 changed files with 10 additions and 9 deletions

Binary file not shown.

View File

@ -30,8 +30,8 @@ public class Esame{
String nome; String nome;
int voto; int voto;
int mat; int mat;
if(sc.hasNextLine()){ if(sc.hasNext()){
nome=sc.nextLine(); nome=sc.next();
if(sc.hasNextInt()){ if(sc.hasNextInt()){
voto=sc.nextInt(); voto=sc.nextInt();
if(sc.hasNextInt()){ if(sc.hasNextInt()){

Binary file not shown.

View File

@ -24,9 +24,7 @@ public class Main{
sc=new Scanner(srcEsami); sc=new Scanner(srcEsami);
e=Esame.read(sc); e=Esame.read(sc);
while(e!=null){ while(e!=null){
System.out.println(e.getVoto()+" "+e.getMat()+" "+e.getNome());
if(e.lookUp(s.getMat())){ if(e.lookUp(s.getMat())){
System.out.println("ok "+e.getVoto());
media+=e.getVoto(); media+=e.getVoto();
i++; i++;
} }
@ -37,6 +35,9 @@ public class Main{
s=Studente.read(sc); s=Studente.read(sc);
} }
System.out.println("lo studente "+s.getNomeCognome()+" ha la media di: "+media/i); if(s!=null)
System.out.println("lo studente "+s.getNomeCognome()+" ha la media di: "+media/i);
else
System.out.println("Impossibile trovare delle corrispondenze.");
} }
} }

Binary file not shown.

View File

@ -26,10 +26,10 @@ public class Studente{
String nome; String nome;
String cnome; String cnome;
int mat; int mat;
if(sc.hasNextLine()){ if(sc.hasNext()){
nome=sc.nextLine(); nome=sc.next();
if(sc.hasNextLine()){ if(sc.hasNext()){
cnome=sc.nextLine(); cnome=sc.next();
if(sc.hasNextInt()){ if(sc.hasNextInt()){
mat=sc.nextInt(); mat=sc.nextInt();
return new Studente(nome, cnome, mat); return new Studente(nome, cnome, mat);