Ok, so i hope i am not going against any rules by posting here... i read and re-read the rules, so if i accidently break one, please let me konw.
I did search google and stuff for this answer, but none of them post or tutorials i watched showed me what i needed.
Ok, so i am trying to make a class (program?) that takes what the user inputs and replies to it.
so i have
import java.util.Scanner; //so i can use the scanner public class ScannerMain { public static void main (String args[]){ Scanner wordscanner = new Scanner(System.in); //setting the scanner boolean con = true; //i am just using this to keep the string repeating after they input, so they can reply to what the computer outputs while (con = true) { String answer; System.out.print("Reply:"); answer = wordscanner.next(); //mostly self explanitory if (answer = "hi"){ /*here is where i get the error.... it says unable to convert String to boolean i tried changed the answer to a boolean, or copying the value of the boolean to a new variable.. but that didn't work. also, i think i may have to word the "hi" differently, what im trying to do with that: is seeing if the user had wrote hi, and if so reply with hello*/ System.out.println("Hello"); }else{ System.out.println("I do not reconize your statement"); } } } }
Again, i did try converting the string to a boolean, but i couldn't seem to get that to work.
Code Without any comments (so you might be able to read the actual code better)
import java.util.Scanner; public class ScannerMain { public static void main (String args[]){ Scanner wordscanner = new Scanner(System.in); boolean con = true; while (con = true) { String answer; System.out.print("Reply:"); answer = wordscanner.next(); if (answer = "hi"){ System.out.println("Hello"); }else{ System.out.println("I do not reconize your statement"); } } } }
The only error I'm getting is at the "unable to convert String to Boolean"