0

So.. I have this code.. And for some reason it says "No Output" I wanted to make a code, where if I put in input .. Let's say "a" it will bring a math formula.. If I print "b" it will bring another math formula.. Please.. Need some help

The code:

import java.util.Scanner;

public class Program
{
    public static void main(String[] args) {
        String[][] dictionary = {{"a", "asociat lui a"}, {"b", "asociat lui b"}, {"c", "asociat lui c"}, {"d", "asociat lui d"}, {"e", "asociat lui e"}};

        Scanner XD=new Scanner(System.in);
        String x=new String();
        x=XD.next();

        if(x=="a"){
            System.out.println(dictionary[0][1]);
        }
        else if(x=="b"){
            System.out.println(dictionary[1][1]);
        }
        else if(x=="c"){
            System.out.println(dictionary[2][1]);
        }
        else if(x == "d"){
            System.out.println(dictionary[3][1]);
        }
        else if(x == "e"){
            System.out.println(dictionary[4][1]);
        }
    }
}
eis
  • 51,991
  • 13
  • 150
  • 199
  • This is now closed as a duplicate, but in short: java strings are generally compared with `.equals()`, not with `==` – eis May 31 '18 at 06:25
  • First learn about string comparison (as stated above) and then learn hashmap, how can you simplify your code using hashmap – Hemant Patel May 31 '18 at 06:33
  • Where and how can I take a look or .. I don't know.. Learn about hashmap.. Sorry if it's a stupid question – user9824940 Jun 03 '18 at 21:20

0 Answers0