#How can i fix this error

15 messages · Page 1 of 1 (latest)

sand sorrelBOT
#

This post has been reserved for your question.

Hey @grim crystal! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

#

Please format your code to make it more readable.
For java, it should look like this:
```​​`​java
public void foo() {

}
​`​```

lilac agateBOT
#

'''import java.util.Scanner;


public class Main {
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       
       
       
      System.out.println("Welcome to your Bank Account");
      System.out.println("Select one of the options");
      System.out.println("1:Deposit ");
       System.out.println("2:Withdraw ");
       System.out.println("3:Transaction History ");
       
      int option = scanner.nextLine();
       
       if(option==1){
           System.out.println("You have chosen to Deposit some money. How much would you like to deposit?");
           
       }
       
   }
} ```
'''

This message has been formatted automatically. You can disable this using /preferences.

proud flame
#

scanner.nextLine returns an string. You need to convert from string to integer in this case.

#

Yes definitely

#

It's exactly the same concept. 1 is an integer, option is a string, in Java you can't compare between different types of values.

Think of it like you're trying to compare apples to cars

#

You can convert from string to integer by doing.

Integer.parseInt(option)

(or parseInteger() on phone so can't remember exactly (sorry about that))

lilac agateBOT
#

and i would make ```java

if(option=______) {

} ```

This message has been formatted automatically. You can disable this using /preferences.

proud flame
#

You can do equality operators between strings by doing

"Hello world!".equals(option)

Where the text inside of the double quotes is how you define a string in Java (and many other programming languages)

Alternatively if you want to ignore case, you can do this:

"Hello world!".equalsIgnoreCase(option)
#

If you want to do this even better, I recommend using enums (one minute)

#

This is 100% doable

#

No problem, I hope I helped in some way here.

#

Also if you have more questions related to this, don't be afraid to ask