2016-10-31 5 views
-6
import java.util.Scanner; 

public class Prova { 
private static Scanner sc; 
private static Scanner s; 
private static Scanner ri; 

public static void main(String[] args) { 
    System.out.println("Ciao, come ti chiami?"); 
    String value; 
    s = new Scanner(System.in); 
    value=s.nextLine(); 
    System.out.println("Oh, " + value + " è un nome fantastico. Adesso ciò che dovrai fare è sceliere un numero n (più piccolo lo prendi e più faceile ti risulterà il problema) "); 
    int i; 
    sc = new Scanner(System.in); 
    i =sc.nextInt(); 
    System.out.println(i*i*4); 
    System.out.println("Che relazione c'è tra il numero scelto da te e quello dato da me ?"); 
    String risposta; 
    ri = new Scanner(System.in); 
    risposta=ri.nextLine(); 
    if (risposta.equals("è il quadrato moltiplicato per 4")){ 
    System.out.println("Complimenti! + 10 punti");} 
    else { System.out.println("Oh no, hai sbaliato! - 2 punto");} 
    System.out.println("Passiamo alla prossima domanda. Chi è il presidente della Repubblica Italiana? (scrivere nome e cognome in questo ordine e tutto minuscolo)"); 
    String risposta1; 
    ri = new Scanner(System.in); 
    risposta1=ri.nextLine(); 
    if (risposta1.equals("sergio mattarella")){ 
     System.out.println("Complimenti! + 5 punti");} 
    else {System.out.println("Oh no, hai sbagliato! - 1 punto"); 
    } 
    if (risposta.equals("è il qaudrato moltiplicato per 4") & risposta1.equals("sergio mattarella")); 
    System.out.println("hai ottwnuto 15 punti");// something does't work here ! how can i say it? do you understandt my question? 

Ich brauche etwas Hilfe, weil es nicht sehr gut funktioniert, können Sie verstehen, was ich meine, wenn ich sage, dass es ein Problem gibt?wenn und sonst nicht funktioniert

+3

Nein, können Sie uns das Problem/Stacktrace geben? –

+1

* Wie * funktioniert es nicht sehr gut? Bitte [lesen Sie, wie Sie gute Fragen stellen können] (http://stackoverflow.com/help/how-to-ask). Und denken Sie daran, dass bei String-Vergleichen zwischen Groß- und Kleinschreibung unterschieden wird. –

+0

Der Code ist sehr schwer zu verstehen, können Sie bitte einige Details hinzufügen – Venkat

Antwort

5
if (risposta.equals("è il qaudrato moltiplicato per 4") & 
risposta1.equals("sergio mattarella")); 
    System.out.println("hai ottwnuto 15 punti"); 

Dies verursacht Ihr Problem. Ändern Sie ihn auf:

if (risposta.equals("è il qaudrato moltiplicato per 4") &&  
    risposta1.equals("sergio mattarella")) { 
    System.out.println("hai ottwnuto 15 punti");// something does't work here ! how can i say it? do you understandt my question? 
} 
  • & sollte & &
  • Sie sich direkt beenden Ihre if (..) eine Erklärung mit a;

Lesen Sie außerdem einige Programmierer-Empfehlungen.

+0

Vielen Dank, Sie lösen mein Problem! – frlaka

+0

In diesem Fall können Sie diese Antwort akzeptieren? :) –

+0

ja, ich kann ich es tun? – frlaka

Verwandte Themen