Saturday, 15 January 2011

java - my if statement wont work? speech synthesizer -



java - my if statement wont work? speech synthesizer -

this question has reply here:

how compare strings in java? 23 answers

hey im making programme in java type console responds computer talking(with sound), im using freetts speech synthesizer. reason when write next code output not want.

import java.util.scanner; import com.sun.speech.freetts.voicemanager; import com.sun.speech.freetts.voice; public class texttospeech { public static void main(string args[]){ scanner input = new scanner(system.in); string userinput = input.nextline(); if(userinput == "hi"){ voice v; voicemanager vm=voicemanager.getinstance(); v=vm.getvoice("kevin16"); v.allocate(); v.speak("hey name jarvis"); input.close(); }else system.out.println("you suck seek again"); } }

when compare reference variables (string reference variables in instance) == comparing operator checks whether refer same object. example;

string s = new string("s"); string s2 = "s"; system.out.println(s==s2);

the above outputs false because s , s2 not refer same string object in memory;

instead, utilize .equals() method compare whether string references meaningfully equal. example;

string s = new string("s"); string s2 = "s"; system.out.println(s.equals(s2));

the above outputs true.

java if-statement speech-synthesis freetts

No comments:

Post a Comment