栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

简单的Java计算器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

简单的Java计算器

package org.com;import java.lang.*; import java.util.*;public class Calculator {     private int solution;     private static int x;     private static int y;     private char operators;    public Calculator()     {         solution = 0;         Scanner operators = new Scanner(System.in);         Scanner operands = new Scanner(System.in);     }    public int addition(int x, int y)     {        return x + y;     }     public int subtraction(int x, int y)     {        return x - y;     }     public int multiplication(int x, int y)     { return x * y;     }     public int division(int x, int y)     {        solution = x / y;        return solution;     }    public void calc(int ops){         x = 4;          System.out.println("operand 2: ");          y = 5;         switch(ops)          {   case(1):     System.out.println(addition(x, y));//    operands.next();     break;   case(2):       System.out.println(subtraction(x, y));    // operands.next();     break;   case(3):       System.out.println(multiplication(x, y));   //  operands.next();     break;   case(4):       System.out.println(division(x, y));  //  operands.next();     break;}     }    public static void main (String[] args)     {       System.out.println("What operation? ('+', '-', '*', '/')");        System.out.println(" Enter 1 for Addition");      System.out.println(" Enter 2 for Subtraction");      System.out.println(" Enter 3 for Multiplication");      System.out.println(" Enter 4 for Division");       Calculator calc = new Calculator();       calc.calc(1);  } }

这会工作



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/440497.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号