Premetto che è la prima volta che programmo in java e questo è il mio primo programma.
Il problema è questo, ho creato un if che, dipende dall'input che gli dai dalla tastiera, stampa a video frasi diverse, però non funziona e non riesco a capire il perché.
Codice:
import java.io.*;
public class Rain{
public static void main (String[] args){
char par;
int k;
System.out.println("Scrivi un numero:");
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader myInput = new BufferedReader(reader);
String str= new String();
try{str = myInput.readLine();
}catch(IOException e){
System.out.println ("Si è verificato un errore: " + e);
System.exit(-1);
}
k = Integer.parseInt(str);
System.out.println ("Scrivi \"ciao\"");
BufferedReader myInput2 = new BufferedReader(reader);
String str2= new String();
try{str2 = myInput2.readLine();
}catch(IOException e){
System.out.println ("Si è verificato un errore: " + e);
System.exit(-1);
}
if(str2 == "ciao") System.out.println(str2);
else System.out.println("Non hai scritto ciao");
}
}
Netbeans non dà nessun errore nella compilazione, qualcuno può aiutarmi?


Rispondi quotando