0

Whenever I input a numbers for example 3,14*10 in nums it throws an exception and I need to be able to input numbers combined with operations like that and then should the program give me the minimum

import java.util.Scanner;

public class Aufgabe3_1 {

    public static void main(String[] args) {
        

        
        int[] nums;
        nums = new int[3];
        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("Bitte geben Sie Drei Zahlen ");
        
        for(int i = 0 ; i < nums.length ; i++) {
        nums[i] = keyboard.nextInt();
        }//end for
        

    }
}
kololo
  • 11
  • 1
  • 1
    Does this answer your question? [How to evaluate a math expression given in string form?](https://stackoverflow.com/questions/3422673/how-to-evaluate-a-math-expression-given-in-string-form) – Federico klez Culloca Nov 08 '21 at 21:40
  • Can you please avoid adding more and more parts of the question to the title and put it in the question body instead? – Federico klez Culloca Nov 08 '21 at 21:58

1 Answers1

1

your input is a double or float so, you would need to check your variable types on your array and change it. Also nextInt() wouldn't fit anymore. Then I would recommend you to use a math parser for Java (just search in the Internet) or you can check for the multiplication symbol when cracking up your expression with regex and then multiplicate your element before and after this symbol. Either way I would say that you should look for: How to evaluate a math expression given in string form? and for: regex

I wish you luck Glados_v27

Glados_v27
  • 11
  • 2
  • i have tried changing nums from int to double but to no avail when I input such numbers it won t accept. – kololo Nov 08 '21 at 21:48
  • Yeah because it can not see the " * " symbol as a real java math operation. You need to make it understandable for java. – Glados_v27 Nov 08 '21 at 21:57