0

Using java to get a string output

My program pretends to get an output ( a string of data) always that I'm sending a string with values ( such as BCI, BCH ... ). In my program I've set a dialog box where I will send the values ( BCI, or BCH , ou even others). I'm expecting to receive "angola" if I send value "BCI" to the program; I'm expecting to receive "testef" if I send value "BCH" to the program; However I'm not getting there.. Here is my code : ------------------------------------------------------ import javax.swing.JOptionPane; public class Passwords1 { public static void main(String[] args) { String BCI; String BCH; String Resposta; BCI = "angola"; BCH = "testef"; Resposta = JOptionPane.showInputDialog(null, "Teste banco?a " ); if( Resposta.equals("BCI") ); { JOptionPane.showMessageDialog(null, BCI );} if ( Resposta.equals("BCH")) { JOptionPane.showMessageDialog(null, BCH );} } }

29th Nov 2017, 5:04 PM
Joao Ferreira
Joao Ferreira - avatar
2 Answers
+ 5
Don't use semicolon after the first if condition.
29th Nov 2017, 5:44 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 1
Thank you @Shamima Yasmin!! I think I found the answer after some hours...:) See below the correct code I was needing. First, it's true your tip! and I've followd it! Second, it was also necessary to remove "null" in: Resposta = JOptionPane.showInputDialog(null, "Teste banco?a " ); ^^^ If you consider necessary, or useful, we can change ideas, my email adress is joaorprferreira@gmail.com many thanks once more! ------------------------------------------------------------------------------------------------- import javax.swing.JOptionPane; public class pass{ public static void main(String[] args) { String BCI; String BCH; String BCA; String resposta; BCI = "angola"; BCH = "testef"; BCA = "estĂĄ a funcionmar?"; resposta = JOptionPane.showInputDialog("QUAL A PASSWORD PRETENDIDA DE ANGOLA ? " ); if(resposta.equals("BCI") ) { JOptionPane.showMessageDialog(null, BCI );} if(resposta.equals("BCH") ) {JOptionPane.showMessageDialog(null, BCH ); } if(resposta.equals("BCA") ) {JOptionPane.showMessageDialog(null, BCA); } } }
29th Nov 2017, 11:59 PM
Joao Ferreira
Joao Ferreira - avatar