Calculadora PROMPT [RESOLVIDO]

Oi pessoal, tou aqui mais uma vez e quero que vocês me ajudem com um problema…

O codigo abaixo está todo certo…
O unico problema é que o 2 argumento sempre sera um sinal de operação (+ ou -, / ou *) só que eu nao sei como fazer para colocar uma operação por exemplo:
2 + 2
Mas dá um erro com o ope dizendo InputMismatch… não sei como faço para poder colocar o sinal de operação no meio dos 3 argumentos…

import java.util.*;

public class calculadora {
	
	public static void main(String[] args) { 

		float x = 0, y = 0, res = 0;
		int ope;
		
		Scanner ent = new Scanner(System.in);
		
		System.out.println("Começe a operação:");
		x = ent.nextFloat();
		ope = ent.nextInt();
		y = ent.nextFloat();
				
		if (args.length > 0) {
			x = Integer.parseInt(args[0]);
		}
		if (args.length > 1) {
			ope = Integer.parseInt(args[1]);
		}
		if (args.length > 2) {
			y = Integer.parseInt(args[2]);
		}
		if (ope == 1) {
			res = x + y;
		}
		if (ope == 2) {
			res = x - y;
		}
		if (ope == 3) {
			res = x / y;
		}
		if (ope == 4) {
			res = x * y;
		}
		
		System.out.println("Resultado:" + res); 

		}  
}

Espero resposta!

Tenta isso

[code]package com.compels.test;

import java.util.*;

public class calculadora {

public static void main( String[] args ){

    float x = 0 , y = 0 , res = 0;
    String ope;

    Scanner ent = new Scanner(System.in);

    System.out.println("Começe a operação:");
    x = ent.nextFloat();
    ope = ent.next();
    y = ent.nextFloat();

    if ( args.length > 0 ){
        x = Integer.parseInt(args[0]);
    }
    if ( args.length > 1 ){
        ope = String.valueOf(args[1]);
    }
    if ( args.length > 2 ){
        y = Integer.parseInt(args[2]);
    }
    if ( ope.equals("+") ){
        res = x + y;
    }
    if ( ope.equals("-") ){
        res = x - y;
    }
    if ( ope.equals("/") ){
        res = x / y;
    }
    if ( ope.equals("*") ){
        res = x * y;
    }

    System.out.println("Resultado:" + res);

}

}
[/code]

Nossa muito bom!
Eu pensei em fazer isso só que não sabia o que usar para pegar o valor de ope, se caso ele fosse string.

O erro estava na obtenção dos argumentos.
Lembrando que deverá obrigatoriamente haver espaços entre os valores:
Exemplo:
2_+2
Onde o sublinhado (
) representa o espaço.

Defini tbm que:

  • sinal de soma
  • sinal de subtração
    x sinal de multiplicação (não obrigatório pois não valido este…)
    : sinal de divisão
import java.util.*;   
  
public class Calculadora {   
       
    public static void main(String[] args) {   
  
        float x = 0, y = 0, res = 0;   
        int ope;   
        String opeS; // Incluí esta linha
           
        Scanner ent = new Scanner(System.in);   
           
        System.out.println("Começe a operação:");   
        x = ent.nextFloat();   
//        ope = ent.nextInt();  //Comentei esta
        opeS = ent.next();		//Incluí esta
        y = ent.nextFloat();   
                   
        if (args.length > 0) {   
            x = Integer.parseInt(args[0]);   
        }   
        if (args.length > 1) {   
//            ope = Integer.parseInt(args[1]); //Comentei esta   
        	opeS = args[1]; //Incluí esta
    	}
        if (args.length > 2) {   
            y = Integer.parseInt(args[2]);   
        }
        
        //Fiz esta validação/conversão
        ope = "+".equals(opeS) 
        		? 1 
        		: "-".equals(opeS) 
        			? 2
					: ":".equals(opeS)
						? 3
						: 4;
        
        if (ope == 1) {   
            res = x + y;   
        }   
        if (ope == 2) {   
            res = x - y;   
        }   
        if (ope == 3) {   
            res = x / y;   
        }   
        if (ope == 4) {   
            res = x * y;   
        }   
           
        System.out.println("Resultado:" + res);   
  
    }     
}