#Why isn't my code registering it as equal to each other

1 messages · Page 1 of 1 (latest)

vague marlin
#
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner keyboardInput = new Scanner(System.in);
    String choice;
    Integer intChoice;
    Boolean choiceOpt = false;

    while (true) {
      System.out.println("Welcome to The Only Shop You Need!\n");
      System.out.println("    1: Purchase Items \n    2: Inventory Report \n    3: Restock \n    4: Modify Items \n    5: Add Item \n    6: Save \n    7: Quit ");
      System.out.print("Choice >>: ");
      choice = keyboardInput.next();
            
      try {
        intChoice = Integer.parseInt(choice);
        for (int i = 1; i > 7; i ++) {
            System.out.println(i);
            if (i == intChoice) {
                choiceOpt = true;
            }
            
        }
        if (choiceOpt) {
          System.out.println("Chosen");
          
        } else {
        System.out.println("Your choice is not one of the options#1.");
        }
      } catch (NumberFormatException ex){ 
          System.out.println("Your choice is not a number.");
      }

    }
      
  }
}
finite salmonBOT
# vague marlin ```java import java.util.*; class Main { public static void main(String[] arg...

Detected code, here are some useful tools:

Formatted code
import java.util. * ;

class Main {
  public static void main(String[] args) {
    Scanner keyboardInput = new Scanner(System.in);
    String choice;
    Integer intChoice;
    Boolean choiceOpt = false;
    while (true) {
      System.out.println("Welcome to The Only Shop You Need!\n");
      System.out.println("    1: Purchase Items \n    2: Inventory Report \n    3: Restock \n    4: Modify Items \n    5: Add Item \n    6: Save \n    7: Quit ");
      System.out.print("Choice >>: ");
      choice = keyboardInput.next();
      try {
        intChoice = Integer.parseInt(choice);
        for (int i = 1; i > 7; i++) {
          System.out.println(i);
          if (i == intChoice) {
            choiceOpt = true;
          }
        }
        if (choiceOpt) {
          System.out.println("Chosen");
        }
        else {
          System.out.println("Your choice is not one of the options#1.");
        }
      } catch (NumberFormatException ex) {
        System.out.println("Your choice is not a number.");
      }
    }
  }
}
#

<@&987246399047479336> please have a look, thanks.

finite salmonBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

eternal onyx
#

nextline , not .next

vague marlin
eternal onyx
#

nextLine

vague marlin
#

Oh SHOOT

eternal onyx
#

my fault, should of capped it

vague marlin
#

Hmm still not working

vague marlin
eternal onyx
#

try to output the input u did

vague marlin
eternal onyx
#

also , if its a menu, your better of with a switch statement then with a loop

vague marlin
#

OH yeah should I just change it now I guess?

eternal onyx
#

yeah , and as your reading text now, u dont need the parse

vague marlin
#

What? wdym by "as your reading text now"

eternal onyx
#

your reading a string, so make the switch on that

vague marlin
#

Oh sure sure thanks!