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 2 of 2

Thread: Dialog box not showing up under if statement

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Dialog box not showing up under if statement

    import javax.swing.JOptionPane;
    import java.util.Scanner;



    public class firstcode {
    public static void main(String[]args) {
    /* LOGICAL OPERATORS
    && = (AND) both conditions must be true
    || = (OR) either conditons must be true
    ! = ( NOT ) reverses boolean value condition
    */
    Scanner input1 = new Scanner(System.in);
    System.out.println("type ( temp ) to run temperature program or type ( game ) to run game program ");
    String response = input1.next();
    if(response.equals("temp")) {
    int temp = Integer.parseInt(JOptionPane.showInputDialog(" whats the temperature "));
    if (temp > 30) {
    System.out.println("its hot outside ");

    }
    else if ( temp >= 18 && temp <= 30) {
    System.out.println("its warm outside ");

    }
    else if (temp < 18) {
    System.out.print("its cold outside " );
    }


    }
    else if(response.equals("game")) {
    Scanner input2 = new Scanner(System.in);
    System.out.println("Type\" Q \" or \"q\" to end the game ");

    String response1 = input2.next();
    if(response1.equals("q")|| response1.equals("Q")) {
    System.out.println("Game is over ");

    }

    else {
    System.out.println("Game is still continuing \"pew pew \"");

    }

    input2.close();


    }

    input1.close();

    }

    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Dialog box not showing up under if statement

    Please add some comments to the code where it is not executing as you expect.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: December 10th, 2019, 06:17 AM
  2. jtable showing the table content but not showing the table headers
    By vimivimal in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 10th, 2017, 01:27 PM
  3. How to turn my If statement into a case/switch statement?
    By blobby404 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: June 19th, 2014, 03:11 PM
  4. JOption Dialog box showing duplicates for each choice
    By makominami in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 6th, 2013, 01:23 AM
  5. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM