r/javahelp • • Mar 05 '23

intellij idea

i tried to make a code that allows the user to input a double number but it only worked if i used a comma instead of a decimal. like if i were to input a number for a price of an item “2.00” would create an error but “2,00” works. my intellij is in english and also i checked the settings on my laptop and it uses a period for money and a comma to group numbers so 40,000.00. what do i do to fix this?

EDIT: this is my code public class Store { String fruit; double price; int quantity;

public Store(String fruit, double price, int quantity, String email) {
    this.fruit = fruit;
    this.price = price;
    this.quantity = quantity;
}

public String getFruit() {
    return fruit;
}

public double getPrice() {
    return price;
}

public int getQuantity() {
    return quantity;
}

}

import java.util.Scanner; public class Customer { public static void main(String[] args) { Customer customers = new Customer(); customers.getProducts(); } public void getProducts() { Scanner scan = new Scanner(System.in); System.out.println("Enter fruit: "); String fruit = scan.nextLine(); System.out.println("Enter price: "); double price = scan.nextDouble(); System.out.println("Enter quantity: "); int quantity = scan.nextInt(); System.out.println("Thank you!"); } }

sorry idk how to get it into the format

https://imgur.com/a/ffi12Og here are screenshots of it. it only runs if i use a comma instead of a decimal

0 Upvotes

11 comments sorted by

•

u/AutoModerator Mar 05 '23

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/roberp81 Mar 05 '23

i can't see your code but you need to define locals

en inglés siempre usan al revés del mundo, que el punto es decimal en lugar de la coma

1

u/agosto-13 Mar 05 '23

i know thats why im confused because intelij is in english but the grammar and the way its set up is in spanish which is why its not letting me use a period

6

u/jocularamity Mar 05 '23

If you post your code, people can help more.

1

u/wildjokers Mar 05 '23

Your title is kind of confusing. Are you getting an error when you compile your code? Or is IntelliJ giving you some error?

1

u/agosto-13 Mar 05 '23

intelij is giving me the error

1

u/morhp Professional Developer Mar 05 '23

nextDouble always requires English format without comma and so on. Like "20.01".

If you write "20,01" instead, nextDouble() will read the "20" as double and leave ",01" sort of hanging there until you try to read that with a following call.

1

u/agosto-13 Mar 05 '23

if you look at the screenshots though if i try to write in the english format it doesn’t run the code and gives me an error. for some reason it only accepts if if i use a comma instead which is the spanish format

2

u/dionthorn this.isAPro=false; this.helping=true; Mar 05 '23

If you can't get reddit's code blocks to play nice use a pastebin link, or github gists:

https://www.reddit.com/r/javahelp/wiki/code_guides/

1

u/AutoModerator Mar 05 '23

It seems that you possibly have a screenshot of code in your post intellij idea in /r/javahelp.

Screenshots of code instead of actual code text is against the Code posting rules of /r/javahelp as is also outlined in the sidebar - Code posting.

  • Never submit screenshots of code instead of code text!

If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images.

If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code.

  • For small bits of code (less than 50 lines in total, single classes only),
    the default code formatter is fine
    (one blank line before the code, then 4 spaces before each line of code).

  • Pastebin for programs that consist of a single class only

  • Gist for multi-class programs, or programs that require additional files

  • Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.

  • Ideone for executable code snippets that use only the console

Please do not reply to this message, because I am a bot. Talk-to-the-bot is the new talk-to-the-hand. If you instead want the classic talk-to-the-hand, just message the moderators. ;)

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.