Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
package expnum;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
     Scanner input = new Scanner(System.in);
     int numbers[];
     int number;
    int word;
     String expression[]={"+" , "-" , "*" , "/"};
     System.out.println("please enter 3 numbers:");
     number=input.nextInt();
     System.out.println("please enter 2 expression (+ , - ,* , /):");
      word = input.nextInt();
  //   public void answer(int expression){}
      class answer 
{
    // public static void answer (String[]args)
    {
        int expression=5;
        switch(expression)
        {
            case 1:  System.out.println(" + ");break;
            case 2:  System.out.println(" - ");break;
            case 3:  System.out.println(" * ");break;
            case 4:  System.out.println(" / ");break;
            default: System.out.println("in valid");break;
    }
}
}

     {
     }
}

is it true?
iwant a program that i give numbers and expression(+ - * / ) and the program give a result.
Is it useful?
Posted

That is how you use a switch but what you have there isn't going to do anything useful for you.

mf_arian wrote:
iwant a program that i give numbers and expression(+ - * / ) and the program give a result.

Did you bother reading the previous answer that I gave you?
 
Share this answer
 
If u getting the expression as integer then u can pass the number to switch block you have written but u if u getting expression(*,+...)then u can pass that expression value the switch block.finally where's the code for expression evaluation..?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900