#Help with text input from user

9 messages · Page 1 of 1 (latest)

dense prairie
#

So my post got closed because it said it's an assignment but i thought we are allowed to get HELP just not answers and if we are making an effort????

This is my code from the previous question:


public class Question2 {

        public static void main(String[] args) {

            Scanner in = new Scanner(System.in);

            while(in.hasNext()) {
                int num1 = in.nextInt();
                String character = in.next();
                int num2 = in.nextInt();
                int sum = 0;

                switch (character) {
                    case "+":
                        sum = num1 + num2;
                        System.out.println(sum);
                        break;

                    case "-":
                        sum = num1 - num2;
                        System.out.println(sum);
                        break;

                    case "x":
                        sum = num1 * num2;
                        System.out.println(sum);
                        break;

                    case "/":
                        double sumD = (double)num1 / (double) num2;
                        System.out.println(sumD);
                        break;

                    default:
                        System.out.println("unknown operator");
                        break;

                }
            }

        }

    }```

I just want help with being pointed in the right direction. I did the previous question and just need to figure out how to extend it.
Thank you.
worthy pulsar
dense prairie
#

well i think its one line

#

in the previous question we just had to deal with mathematical expressions with only 2 variables

#

here we need to eccommodate the variable length

#

so arrays need to be used ?

#

It says at the end of first picture, 'Test cases will only provide one expression on one line. Multiples lines do not need to be accommodated.'

warm pasture
#

what does this have to do with JavaFX?

dense prairie
#

Oh sorry