Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: What's wrong with this code

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What's wrong with this code

    in this code if i input exit this loop must be ended but if i enter random string such as quit this loop quit i want to quit only i enter exit.My english kinda bad sorry for that.Ty for helping
    public static void main(String[] args) {
    Scanner input= new Scanner(System.in);
    String word;
    String e;

    HashMap<String,String> sozluk=new HashMap<String,String>();
    sozluk.put("book","kitap");
    sozluk.put("table","masa");
    sozluk.put("chair","sandalye");
    sozluk.put("notebook","defter");
    sozluk.put("printer","yazıcı");

    do {
    System.out.println("lütfen ingilizce kelimeyi giriniz:");
    word=input.nextLine();

    System.out.println("ingilizce kelime karşılığı olan şey: "+sozluk.get(word));
    System.out.println("çıkmak istiyormusunuz");
    e=input.nextLine();

    } while(e=="exit");



    System.out.println("exit success");

  2. #2
    Junior Member
    Join Date
    Apr 2019
    Posts
    25
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: What's wrong with this code

    change } while(e=="exit"); to } while (!"exit".equals(e));

    public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            String word = null;
            String e = null;
     
            HashMap<String, String> sozluk = new HashMap<String, String>();
            sozluk.put("book", "kitap");
            sozluk.put("table", "masa");
            sozluk.put("chair", "sandalye");
            sozluk.put("notebook", "defter");
            sozluk.put("printer", "yazıcı");
     
            do {
                System.out.println("lütfen ingilizce kelimeyi giriniz:");
                word = input.nextLine();
     
                System.out.println("ingilizce kelime karşılığı olan şey: " + sozluk.get(word));
                System.out.println("çıkmak istiyormusunuz");
                e = input.nextLine();
            } while (!"exit".equals(e));
     
            System.out.println("exit success");
        }

  3. #3
    Junior Member
    Join Date
    May 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with this code

    it works i really really thank you. you are awesome ty for helping me )))))))))))))))))))))))))

Similar Threads

  1. what's wrong with this code ?? HELP
    By Roosh in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 14th, 2014, 10:35 AM
  2. What is wrong with my code?
    By aznlitomik3 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: June 13th, 2014, 08:54 AM
  3. What's wrong with my code?
    By shen in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 18th, 2013, 06:34 AM
  4. What is wrong with my code?
    By unleashed-my-freedom in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2012, 12:41 AM
  5. What is the wrong with this code?
    By Subhasri in forum AWT / Java Swing
    Replies: 1
    Last Post: September 29th, 2011, 08:14 AM

Tags for this Thread