3
I wanted to make a scheme to confirm a question. If the answer was Yes to the question, an ok message would appear. If it was No or different from Yes, I would ask if the person would like to confirm again. I made this algorithm there, but it does not enter the loop.
package resposta;
import java.util.Scanner;
public class Resposta {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Confirma?");
String resp = " ";
String conf = sc.nextLine();
while(resp.equals("s")){
if(resp == "s"){
System.out.println("confirmado");
}else{
String resp2 = "Confirme?";
conf = sc.nextLine();
conf = conf + 1;
}
}
sc.close();
}
}
Why do you wear
resp
andconf
as two variables and not just one?– Victor Stafusa
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero