How do i connect between user input(Scanner) and if condition in Java2019 Community Moderator ElectionHow do I efficiently iterate over each entry in a Java Map?What is the difference between public, protected, package-private and private in Java?How do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How to get an enum value from a string value in Java?How do I determine whether an array contains a particular value in Java?How do I declare and initialize an array in Java?How to split a string in JavaHow do I convert a String to an int in Java?

If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?

Brexit - No Deal Rejection

PTIJ: Who should I vote for? (21st Knesset Edition)

What options are left, if Britain cannot decide?

A single argument pattern definition applies to multiple-argument patterns?

Does this sum go infinity?

Bach's Toccata and Fugue in D minor breaks the "no parallel octaves" rule?

Happy pi day, everyone!

Is it insecure to send a password in a `curl` command?

How to write cleanly even if my character uses expletive language?

Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?

Is there a place to find the pricing for things not mentioned in the PHB? (non-magical)

Why does overlay work only on the first tcolorbox?

What are substitutions for coconut in curry?

combinatorics floor summation

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

Examples of transfinite towers

Why is the President allowed to veto a cancellation of emergency powers?

Adventure Game (text based) in C++

Describing a chess game in a novel

Can I use USB data pins as power source

Official degrees of earth’s rotation per day

Have the tides ever turned twice on any open problem?

How to make healing in an exploration game interesting



How do i connect between user input(Scanner) and if condition in Java



2019 Community Moderator ElectionHow do I efficiently iterate over each entry in a Java Map?What is the difference between public, protected, package-private and private in Java?How do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How to get an enum value from a string value in Java?How do I determine whether an array contains a particular value in Java?How do I declare and initialize an array in Java?How to split a string in JavaHow do I convert a String to an int in Java?










-3















I know i have to use scanner and if condition but i don't know how to connect them



Example:
Are you willing to convert weight or height?
(user input= weight)
Will it be for imperial unit or metric unit?
(user input=metric)
Please provide the weight information in kg
(user input=75)
Your weight in kgs 75.00 is equal to 165.38 in pounds










share|improve this question

















  • 1





    Use local variables.

    – Dawood ibn Kareem
    Mar 5 at 19:42















-3















I know i have to use scanner and if condition but i don't know how to connect them



Example:
Are you willing to convert weight or height?
(user input= weight)
Will it be for imperial unit or metric unit?
(user input=metric)
Please provide the weight information in kg
(user input=75)
Your weight in kgs 75.00 is equal to 165.38 in pounds










share|improve this question

















  • 1





    Use local variables.

    – Dawood ibn Kareem
    Mar 5 at 19:42













-3












-3








-3


1






I know i have to use scanner and if condition but i don't know how to connect them



Example:
Are you willing to convert weight or height?
(user input= weight)
Will it be for imperial unit or metric unit?
(user input=metric)
Please provide the weight information in kg
(user input=75)
Your weight in kgs 75.00 is equal to 165.38 in pounds










share|improve this question














I know i have to use scanner and if condition but i don't know how to connect them



Example:
Are you willing to convert weight or height?
(user input= weight)
Will it be for imperial unit or metric unit?
(user input=metric)
Please provide the weight information in kg
(user input=75)
Your weight in kgs 75.00 is equal to 165.38 in pounds







java conditional java.util.scanner






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 5 at 19:40









Selim SariSelim Sari

1




1







  • 1





    Use local variables.

    – Dawood ibn Kareem
    Mar 5 at 19:42












  • 1





    Use local variables.

    – Dawood ibn Kareem
    Mar 5 at 19:42







1




1





Use local variables.

– Dawood ibn Kareem
Mar 5 at 19:42





Use local variables.

– Dawood ibn Kareem
Mar 5 at 19:42












2 Answers
2






active

oldest

votes


















1














Scanner scanner = new Scanner(System.in);
System.out.println("Enter an input");
String input= scanner.next();


You can start by putting the user input into a variable. Depending on the flow of your program, you might need to parse the input into either integer or float.



int integerinput = Integer.parseInt(input);
float floatInput = Float.parseFloat(input);


From there, you can start doing the comparison. You have to be careful when parsing information, if the user entered a word and you try to convert that into either integer or float, you will get an exception.






share|improve this answer






























    0














    You should get user’s input just once:
    String answer = ask.nextLine();
    And then inspect the input with if():
    if (answer.equals("heght"))
    // heght conversion goes here

    else
    // weght conversion goes here






    share|improve this answer























    • i used this and it gives me an error called cannot find symbol

      – Selim Sari
      Mar 5 at 23:36










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55010332%2fhow-do-i-connect-between-user-inputscanner-and-if-condition-in-java%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter an input");
    String input= scanner.next();


    You can start by putting the user input into a variable. Depending on the flow of your program, you might need to parse the input into either integer or float.



    int integerinput = Integer.parseInt(input);
    float floatInput = Float.parseFloat(input);


    From there, you can start doing the comparison. You have to be careful when parsing information, if the user entered a word and you try to convert that into either integer or float, you will get an exception.






    share|improve this answer



























      1














      Scanner scanner = new Scanner(System.in);
      System.out.println("Enter an input");
      String input= scanner.next();


      You can start by putting the user input into a variable. Depending on the flow of your program, you might need to parse the input into either integer or float.



      int integerinput = Integer.parseInt(input);
      float floatInput = Float.parseFloat(input);


      From there, you can start doing the comparison. You have to be careful when parsing information, if the user entered a word and you try to convert that into either integer or float, you will get an exception.






      share|improve this answer

























        1












        1








        1







        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter an input");
        String input= scanner.next();


        You can start by putting the user input into a variable. Depending on the flow of your program, you might need to parse the input into either integer or float.



        int integerinput = Integer.parseInt(input);
        float floatInput = Float.parseFloat(input);


        From there, you can start doing the comparison. You have to be careful when parsing information, if the user entered a word and you try to convert that into either integer or float, you will get an exception.






        share|improve this answer













        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter an input");
        String input= scanner.next();


        You can start by putting the user input into a variable. Depending on the flow of your program, you might need to parse the input into either integer or float.



        int integerinput = Integer.parseInt(input);
        float floatInput = Float.parseFloat(input);


        From there, you can start doing the comparison. You have to be careful when parsing information, if the user entered a word and you try to convert that into either integer or float, you will get an exception.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 5 at 19:57









        SemjeromeSemjerome

        386




        386























            0














            You should get user’s input just once:
            String answer = ask.nextLine();
            And then inspect the input with if():
            if (answer.equals("heght"))
            // heght conversion goes here

            else
            // weght conversion goes here






            share|improve this answer























            • i used this and it gives me an error called cannot find symbol

              – Selim Sari
              Mar 5 at 23:36















            0














            You should get user’s input just once:
            String answer = ask.nextLine();
            And then inspect the input with if():
            if (answer.equals("heght"))
            // heght conversion goes here

            else
            // weght conversion goes here






            share|improve this answer























            • i used this and it gives me an error called cannot find symbol

              – Selim Sari
              Mar 5 at 23:36













            0












            0








            0







            You should get user’s input just once:
            String answer = ask.nextLine();
            And then inspect the input with if():
            if (answer.equals("heght"))
            // heght conversion goes here

            else
            // weght conversion goes here






            share|improve this answer













            You should get user’s input just once:
            String answer = ask.nextLine();
            And then inspect the input with if():
            if (answer.equals("heght"))
            // heght conversion goes here

            else
            // weght conversion goes here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 5 at 21:05









            user11156080user11156080

            1




            1












            • i used this and it gives me an error called cannot find symbol

              – Selim Sari
              Mar 5 at 23:36

















            • i used this and it gives me an error called cannot find symbol

              – Selim Sari
              Mar 5 at 23:36
















            i used this and it gives me an error called cannot find symbol

            – Selim Sari
            Mar 5 at 23:36





            i used this and it gives me an error called cannot find symbol

            – Selim Sari
            Mar 5 at 23:36

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55010332%2fhow-do-i-connect-between-user-inputscanner-and-if-condition-in-java%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович