连减代码
⑴ C#窗口计算器代码
很简单的啊,你找个值SUM记录1+2的结果 初值为0,判断如果为0 就做1+2.如果不为0就做SUM+2,这样一直按等于就自己加啊
⑵ java算24点代码:输入4个数算24点,能够在命令提示符下就可以运行。100多
import java.util.Scanner;
/** 给定4个数字计算24 */
public class Core {
private double expressionResult = 24;
// private int maxLine=10;
private boolean error = true;
private double numbers[] = new double[4];
public Object resultReturn;
/**
* 该对象拥有3个私有变量 expressionResult,所需结果 maxLine,输出结果每页行数 error,是否出错
* numbers[4],记录用来运算的4个数
*
* 其次,该对象拥有以下方法供外部调用 setNumbers(double[] <运算的数>) 输入用来运算的数,4个时才能计算,无返回
* setMaxLine(int <行数>) 输入每页的行数,无返回 getMaxLine() 返回每页的行数,类型为int
* setExpressionResult(double <所需结果>) 输入所需结果,无返回 getExpressionResult()
* 返回所需结果,类型为double getExpression() 返回可得出所需结果的表达式,类型为字符串数组
*
* 最后,私有方法均为计算与表达式转换部分
*/
// 测试使用
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] arr = new int[4];
System.out.print("输入第一个数:");
arr[0] = scanner.nextInt();
System.out.print("输入第二个数:");
arr[1] = scanner.nextInt();
System.out.print("输入第三个数:");
arr[2] = scanner.nextInt();
System.out.print("输入第四个数:");
arr[3] = scanner.nextInt();
Core s = new Core();
s.setNumbers(arr);
String[] output = s.getExpression();
for (int i = 0; i < output.length; i++) {
System.out.println(output[i]);
}
}
/** 设定被计算的四个数,由于是数组,所以具有容错功能(不为4个数) */
public void setNumbers(double[] n) {
if (n.length == 4) {
error = false;
numbers = n;
} else
error = true;
}
public void setNumbers(int[] n) {
if (n.length == 4) {
error = false;
for (int i = 0; i < 4; i++) {
numbers[i] = n[i];
}
} else
error = true;
}
/** 设定每页显示的行数 */
// public void setMaxLine(int n) {
// if (n>0) {
// maxLine=n;
// }
// }
// /** 返回每页显示的行数 */
// public int getMaxLine() {
// return maxLine;
// }
/** 设定需要得到的结果 */
public void setExpressionResult(double n) {
expressionResult = n;
}
/** 返回所需结果 */
public double expressionResult() {
return expressionResult;
}
/** 返回符合条件的表达式 */
public String[] getExpression() {
if (!error) {
String[] expression = calculate(numbers);
return expression;
} else
return new String[] { "出错了,输入有误" };
}
/** cal24(),输出结果为24的表达式 */
private String[] calculate(double[] n) {
if (n.length != 4)
return new String[] { "Error" };
double[] n1 = new double[3];
double[] n2 = new double[2];
String[] resultString = new String[1024]; // 最多1000组解,暂时未溢出
int count = 0;
boolean isRepeat = false;
for (int t1 = 0; t1 < 6; t1++) {
for (int c1 = 0; c1 < 6; c1++) {
for (int t2 = 0; t2 < 3; t2++) {
for (int c2 = 0; c2 < 6; c2++) {
for (int c3 = 0; c3 < 6; c3++) {
if ((c1 / 3 == c2 / 3 && (c1 % 3) * (c2 % 3) != 0)
|| (c2 / 3 == c3 / 3 && (c2 % 3) * (c3 % 3) != 0)
|| (c1 / 3 == c3 / 3
&& (c1 % 3) * (c3 % 3) != 0 && t2 == 2)) {
// 去除连减连除的解,因为x/(y/z)=x*z/y
continue;
}
n1 = cal1(n, t1, c1);
n2 = cal2(n1, t2, c2);
double result = cal(n2[0], n2[1], c3);
if ((result - expressionResult) < 0.00000001
&& (expressionResult - result) < 0.00000001) {
resultString[count] = calString(n, t1, c1, t2,
c2, c3)
+ "=" + (int) expressionResult;
for (int i = 0; i < count; i++) {
isRepeat = false;
if (resultString[i]
.equals(resultString[count])) { // 去除完全重复的解
isRepeat = true;
break; // 提前退出循环
}
}
if (c1 == c2 && c2 == c3 && c1 % 3 == 0
&& t1 + t2 != 0) { // 连加连乘
isRepeat = true;
}
if (!isRepeat) {
count++;
}
}
}
}
}
}
}
if (count == 0)
return new String[] { "该组数无解" };
String[] resultReturn = new String[count];
System.array(resultString, 0, resultReturn, 0, count);
return resultReturn;
}
/** cal1(),将4个数计算一次后返回3个数 */
private double[] cal1(double[] n, int t, int c) { // t为原来的t1,c为原来的c1
double[] m = new double[3];
switch (t) {
case 0:
m[1] = n[2];
m[2] = n[3];
m[0] = cal(n[0], n[1], c);
break;
case 1:
m[1] = n[1];
m[2] = n[3];
m[0] = cal(n[0], n[2], c);
break;
case 2:
m[1] = n[1];
m[2] = n[2];
m[0] = cal(n[0], n[3], c);
break;
case 3:
m[1] = n[0];
m[2] = n[3];
m[0] = cal(n[1], n[2], c);
break;
case 4:
m[1] = n[0];
m[2] = n[2];
m[0] = cal(n[1], n[3], c);
break;
default:
m[1] = n[0];
m[2] = n[1];
m[0] = cal(n[2], n[3], c);
}
return m;
}
/** cal2(),将3个数计算一次后返回2个数 */
private double[] cal2(double[] n, int t, int c) { // t为原来的t2,c为原来的c2
double[] m = new double[2];
switch (t) {
case 0:
m[1] = n[2];
m[0] = cal(n[0], n[1], c);
break;
case 1:
m[1] = n[1];
m[0] = cal(n[0], n[2], c);
break;
default:
m[1] = n[0];
m[0] = cal(n[1], n[2], c);
}
return m;
}
/** cal(),将2个数计算后返回结果 */
private double cal(double n1, double n2, int c) { // n1,n2为运算数,c为运算类型
switch (c) {
case 0:
return n1 + n2;
case 1:
return n1 - n2;
case 2:
return n2 - n1;
case 3:
return n1 * n2;
case 4:
if (n2 == 0)
return 9999; // 使计算结果必不为24
else
return n1 / n2;
default:
if (n1 == 0)
return 9999; // 同上
else
return n2 / n1;
}
}
/** calString(),输出表达式 */
private String calString(double[] n, int t1, int c1, int t2, int c2, int c3) {
String[] nString = new String[4];
switch (t1) {
case 0:
nString[0] = calString2("" + (int) n[0], "" + (int) n[1], c1);
nString[1] = "" + (int) n[2];
nString[2] = "" + (int) n[3];
break;
case 1:
nString[0] = calString2("" + (int) n[0], "" + (int) n[2], c1);
nString[1] = "" + (int) n[1];
nString[2] = "" + (int) n[3];
break;
case 2:
nString[0] = calString2("" + (int) n[0], "" + (int) n[3], c1);
nString[1] = "" + (int) n[1];
nString[2] = "" + (int) n[2];
break;
case 3:
nString[0] = calString2("" + (int) n[1], "" + (int) n[2], c1);
nString[1] = "" + (int) n[0];
nString[2] = "" + (int) n[3];
break;
case 4:
nString[0] = calString2("" + (int) n[1], "" + (int) n[3], c1);
nString[1] = "" + (int) n[0];
nString[2] = "" + (int) n[2];
break;
default:
nString[0] = calString2("" + (int) n[2], "" + (int) n[3], c1);
nString[1] = "" + (int) n[0];
nString[2] = "" + (int) n[1];
}
if ((c2 / 3 > c1 / 3 && (t2 != 2 || c2 / 3 == c3 / 3))
|| ((c3 / 3 > c1 / 3 + c2 / 3) && t2 == 2)
|| (c3 == 1 && c1 / 3 == 0)) // 特定情况下加上一个括号*****************************
nString[0] = '(' + nString[0] + ')';
switch (t2) {
case 0:
nString[0] = calString2(nString[0], "" + nString[1], c2);
nString[1] = nString[2];
break;
case 1:
nString[0] = calString2(nString[0], nString[2], c2);
break;
default:
nString[3] = nString[0];
nString[0] = calString2(nString[1], nString[2], c2);
nString[1] = nString[3];
}
if (c3 / 3 > c2 / 3 || (c3 == 2 && nString[0].indexOf('+') >= 0)) // 特定情况下加上一个括号*****************************
nString[0] = '(' + nString[0] + ')';
return calString2(nString[0], nString[1], c3);
}
/** calString(),根据符号输出一部运算表达式 */
private String calString2(String n1, String n2, int c) {
switch (c) {
case 0:
return n1 + '+' + n2;
case 1:
return n1 + '-' + n2;
case 2:
return n2 + '-' + n1;
case 3:
return n1 + '*' + n2;
case 4:
return n1 + '/' + n2;
default:
return n2 + '/' + n1;
}
}
}
⑶ C#实现计算器,可以连加、连减、连乘、连除;能实现混合运算 邮箱:[email protected]
以下代码可作为初学C#的朋友学习借鉴,技术无止境,希望以下的代码能起到抛砖引玉的作用。using System;
using System.Windows.Forms;
using System.Drawing;
publicclass win:Form {
Button[] b =new Button[10];
Button bDot,bPlus,bSub,bMul,bDiv,bEqu,bClr;
Panel panCalc;
TextBox txtCalc;
Double dblAcc;
Double dblSec;
bool blnClear,blnFrstOpen;
String strOper;
public win() {
try {
this.Text="Calculator";
panCalc=new Panel();
txtCalc =new TextBox();
txtCalc.Location =new Point(10,10);
txtCalc.Size=new Size(150,10);
txtCalc.ReadOnly=true;
txtCalc.RightToLeft=RightToLeft.Yes;
panCalc.Size=new Size(200,200);
panCalc.BackColor=Color.Aqua;
panCalc.Controls.Add(txtCalc);
addButtons(panCalc);
this.Size=new Size(200,225);
this.Controls.Add(panCalc);
dblAcc=0;
dblSec=0;
blnFrstOpen=true;
blnClear=false;
strOper=new String('=',1);
}
catch (Exception e) {
Console.WriteLine("error ...... "+ e.StackTrace);
}
}
privatevoid addButtons(Panel p) {
for (int i=0;i<=9;i++) {
b[i]=new Button();
b[i].Text=Convert.ToString(i);
b[i].Size=new Size(25,25);
b[i].BackColor=Color.White;
b[i].Click+=new EventHandler(btn_clk);
p.Controls.Add(b[i]);
}
b[0].Location=new Point(10,160);
b[1].Location=new Point(10,120);
b[4].Location=new Point(10,80);
b[7].Location=new Point(10,40);
b[2].Location=new Point(50,120);
b[5].Location=new Point(50,80);
b[8].Location=new Point(50,40);
b[3].Location=new Point(90,120);
b[6].Location=new Point(90,80);
b[9].Location=new Point(90,40);
bDot=new Button();
bDot.Size=new Size(25,25);
bDot.Location=new Point(50,160);
bDot.BackColor=Color.White;
bDot.Text=".";
bDot.Click+=new EventHandler(btn_clk);
bPlus=new Button();
bPlus.Size=new Size(25,25);
bPlus.Location=new Point(130,160);
bPlus.BackColor=Color.White;
bPlus.Text="+";
bPlus.Click+=new EventHandler(btn_Oper);
bSub=new Button();
bSub.Size=new Size(25,25);
bSub.Location=new Point(130,120);
bSub.BackColor=Color.White;
bSub.Text="-";
bSub.Click+=new EventHandler(btn_Oper);
bMul=new Button();
bMul.Size=new Size(25,25);
bMul.Location=new Point(130,80);
bMul.BackColor=Color.White;
bMul.Text="*";
bMul.Click+=new EventHandler(btn_Oper);
bDiv=new Button();
bDiv.Size=new Size(25,25);
bDiv.Location=new Point(130,40);
bDiv.BackColor=Color.White;
bDiv.Text="/";
bDiv.Click+=new EventHandler(btn_Oper);
bEqu=new Button();
bEqu.Size=new Size(25,25);
bEqu.Location=new Point(90,160);
bEqu.BackColor=Color.White;
bEqu.Text="=";
bEqu.Click+=new EventHandler(btn_equ);
bClr=new Button();
bClr.Size=new Size(20,45);
bClr.Location=new Point(170,40);
bClr.BackColor=Color.Orange;
bClr.Text="AC";
bClr.Click+=new EventHandler(btn_clr);
p.Controls.Add(bDot);
p.Controls.Add(bPlus);
p.Controls.Add(bSub);
p.Controls.Add(bMul);
p.Controls.Add(bDiv);
p.Controls.Add(bEqu);
p.Controls.Add(bClr);
}
privatevoid btn_clk(object obj,EventArgs ea) {
if(blnClear)
txtCalc.Text="";
Button b3=(Button)obj;
txtCalc.Text+=b3.Text;
if (txtCalc.Text==".")
txtCalc.Text="0.";
dblSec=Convert.ToDouble(txtCalc.Text);
blnClear=false;
}
privatestaticvoid Main() {
Application.Run(new win());
}
privatevoid btn_Oper(object obj,EventArgs ea) {
Button tmp=(Button)obj;
strOper=tmp.Text;
if (blnFrstOpen)
dblAcc=dblSec;
else calc();
blnFrstOpen=false;
blnClear=true;
}
privatevoid btn_clr(object obj,EventArgs ea) {
clear();
}
privatevoid btn_equ(object obj,EventArgs ea) {
calc();
}
privatevoid calc() {
switch(strOper) {
case"+":
dblAcc+=dblSec;
break;
case"-":
dblAcc-=dblSec;
break;
case"*":
dblAcc*=dblSec;
break;
case"/":
dblAcc/=dblSec;
break;
}
strOper="=";
blnFrstOpen=true;
txtCalc.Text=Convert.ToString(dblAcc);
dblSec=dblAcc;
}
privatevoid clear() {
dblAcc=0;
dblSec=0;
blnFrstOpen=true;
txtCalc.Text="";
txtCalc.Focus();
}
}
⑷ 计算器上怎样算连加连乘或连减连除的
就是3+2,+2,+2.呗
类似这种代码:
等于号被按下:
如果(最后一次运算符=“+”)
编辑框3.内容=编辑框3.内容+编辑框2.内容
--------
具体你的源码是怎么写的俺不清楚,照上面的格式写就可以了。
⑸ 用C语言做一个可进行加减乘除的400位计算器(求思路)
这个可以用一位全加器的思路解决,用一个我有不限位数加法的C语言代码,做ACM的时候的,你再联想一下就可以写出来了。
思路,用一个大数组,一位一位的加。
代码:
#include<stdio.h>
intmain()
{
inta[240]={0},b[240]={0},c[241]={0};
inti,ka,kb,k;
chara1[240],b1[240];
gets(a1);
ka=strlen(a1);
gets(b1);
kb=strlen(b1);
if(ka>=kb)k=ka;
elsek=kb;
for(i=0;i<ka;i++)
a[i]=a1[ka-i-1]-'0';
for(i=0;i<kb;i++)
b[i]=b1[kb-i-1]-'0';
for(i=0;i<k;i++)
{
c[i]=a[i]+b[i]+c[i];
c[i+1]=c[i+1]+c[i]/10;
c[i]=c[i]%10;
}
if(c[k])k++;
for(i=k-1;i>=0;i--)
printf("%d",c[i]);
getchar();
return0;
}
这个只有240位,你可以将数组改大点,但是C必须比加数多一位,否则溢出。
楼上几位太不给力了啊,不知道从哪儿粘贴来MFC的代码,还是工程文件中的一个子文件。。。这根本编译不通的,有本事直接把界面一起拷贝给提问者算了。。。
附上运行结果:
⑹ delphi计算器的自加。。。连加连减连乘连除
你的“=”只处理了单次,怎么能计算出连续的加减乘除呢?
如果想要学习编程思路
http://www.qqgb.com/Program/Delphi/DelphiSource/Program_58628.html
下载慢慢研究
⑺ 问什么这个程序连加可以,但是连减,连乘,连除不对呢
你把代码粘出来
⑻ 求Java简单计算器代码(加减乘除就可以了,但能连加、连减、连乘、连除,小数零点几也可以输入)
要GUI吗?
有邮件吧?随便做了一个,发给你啊
⑼ 急求 JAVA的 算24点的代码!进来看!有特别要求!
package ceshi;
/** 给定4个数字计算24 */
public class Core {
private double expressionResult = 24;
// private int maxLine=10;
private boolean error = true;
private double numbers[] = new double[4];
public Object resultReturn;
/**
* 该对象拥有3个私有变量 expressionResult,所需结果 maxLine,输出结果每页行数 error,是否出错
* numbers[4],记录用来运算的4个数
*
* 其次,该对象拥有以下方法供外部调用 setNumbers(double[] <运算的数>) 输入用来运算的数,4个时才能计算,无返回
* setMaxLine(int <行数>) 输入每页的行数,无返回 getMaxLine() 返回每页的行数,类型为int
* setExpressionResult(double <所需结果>) 输入所需结果,无返回 getExpressionResult()
* 返回所需结果,类型为double getExpression() 返回可得出所需结果的表达式,类型为字符串数组
*
* 最后,私有方法均为计算与表达式转换部分
*/
// 测试使用
public static void main(String[] args) {
Core s = new Core();
s.setNumbers(new int[] { 3, 4, 8, 6 });
String[] output = s.getExpression();
for (int i = 0; i < output.length; i++) {
System.out.println(output[i]);
}
}
/** 设定被计算的四个数,由于是数组,所以具有容错功能(不为4个数) */
public void setNumbers(double[] n) {
if (n.length == 4) {
error = false;
numbers = n;
} else
error = true;
}
public void setNumbers(int[] n) {
if (n.length == 4) {
error = false;
for (int i = 0; i < 4; i++) {
numbers[i] = n[i];
}
} else
error = true;
}
/** 设定每页显示的行数 */
// public void setMaxLine(int n) {
// if (n>0) {
// maxLine=n;
// }
// }
// /** 返回每页显示的行数 */
// public int getMaxLine() {
// return maxLine;
// }
/** 设定需要得到的结果 */
public void setExpressionResult(double n) {
expressionResult = n;
}
/** 返回所需结果 */
public double expressionResult() {
return expressionResult;
}
/** 返回符合条件的表达式 */
public String[] getExpression() {
if (!error) {
String[] expression = calculate(numbers);
return expression;
} else
return new String[] { "出错了,输入有误" };
}
/** cal24(),输出结果为24的表达式 */
private String[] calculate(double[] n) {
if (n.length != 4)
return new String[] { "Error" };
double[] n1 = new double[3];
double[] n2 = new double[2];
String[] resultString = new String[1024]; // 最多1000组解,暂时未溢出
int count = 0;
boolean isRepeat = false;
for (int t1 = 0; t1 < 6; t1++) {
for (int c1 = 0; c1 < 6; c1++) {
for (int t2 = 0; t2 < 3; t2++) {
for (int c2 = 0; c2 < 6; c2++) {
for (int c3 = 0; c3 < 6; c3++) {
if ((c1 / 3 == c2 / 3 && (c1 % 3) * (c2 % 3) != 0)
|| (c2 / 3 == c3 / 3 && (c2 % 3) * (c3 % 3) != 0)
|| (c1 / 3 == c3 / 3
&& (c1 % 3) * (c3 % 3) != 0 && t2 == 2)) {
// 去除连减连除的解,因为x/(y/z)=x*z/y
continue;
}
n1 = cal1(n, t1, c1);
n2 = cal2(n1, t2, c2);
double result = cal(n2[0], n2[1], c3);
if ((result - expressionResult) < 0.00000001
&& (expressionResult - result) < 0.00000001) {
resultString[count] = calString(n, t1, c1, t2,
c2, c3)
+ "=" + (int) expressionResult;
for (int i = 0; i < count; i++) {
isRepeat = false;
if (resultString[i]
.equals(resultString[count])) { // 去除完全重复的解
isRepeat = true;
break; // 提前退出循环
}
}
if (c1 == c2 && c2 == c3 && c1 % 3 == 0
&& t1 + t2 != 0) { // 连加连乘
isRepeat = true;
}
if (!isRepeat) {
count++;
}
}
}
}
}
}
}
if (count == 0)
return new String[] { "该组数无解" };
String[] resultReturn = new String[count];
System.array(resultString, 0, resultReturn, 0, count);
return resultReturn;
}
/** cal1(),将4个数计算一次后返回3个数 */
private double[] cal1(double[] n, int t, int c) { // t为原来的t1,c为原来的c1
double[] m = new double[3];
switch (t) {
case 0:
m[1] = n[2];
m[2] = n[3];
m[0] = cal(n[0], n[1], c);
break;
case 1:
m[1] = n[1];
m[2] = n[3];
m[0] = cal(n[0], n[2], c);
break;
case 2:
m[1] = n[1];
m[2] = n[2];
m[0] = cal(n[0], n[3], c);
break;
case 3:
m[1] = n[0];
m[2] = n[3];
m[0] = cal(n[1], n[2], c);
break;
case 4:
m[1] = n[0];
m[2] = n[2];
m[0] = cal(n[1], n[3], c);
break;
default:
m[1] = n[0];
m[2] = n[1];
m[0] = cal(n[2], n[3], c);
}
return m;
}
/** cal2(),将3个数计算一次后返回2个数 */
private double[] cal2(double[] n, int t, int c) { // t为原来的t2,c为原来的c2
double[] m = new double[2];
switch (t) {
case 0:
m[1] = n[2];
m[0] = cal(n[0], n[1], c);
break;
case 1:
m[1] = n[1];
m[0] = cal(n[0], n[2], c);
break;
default:
m[1] = n[0];
m[0] = cal(n[1], n[2], c);
}
return m;
}
/** cal(),将2个数计算后返回结果 */
private double cal(double n1, double n2, int c) { // n1,n2为运算数,c为运算类型
switch (c) {
case 0:
return n1 + n2;
case 1:
return n1 - n2;
case 2:
return n2 - n1;
case 3:
return n1 * n2;
case 4:
if (n2 == 0)
return 9999; // 使计算结果必不为24
else
return n1 / n2;
default:
if (n1 == 0)
return 9999; // 同上
else
return n2 / n1;
}
}
/** calString(),输出表达式 */
private String calString(double[] n, int t1, int c1, int t2, int c2, int c3) {
String[] nString = new String[4];
switch (t1) {
case 0:
nString[0] = calString2("" + (int) n[0], "" + (int) n[1], c1);
nString[1] = "" + (int) n[2];
nString[2] = "" + (int) n[3];
break;
case 1:
nString[0] = calString2("" + (int) n[0], "" + (int) n[2], c1);
nString[1] = "" + (int) n[1];
nString[2] = "" + (int) n[3];
break;
case 2:
nString[0] = calString2("" + (int) n[0], "" + (int) n[3], c1);
nString[1] = "" + (int) n[1];
nString[2] = "" + (int) n[2];
break;
case 3:
nString[0] = calString2("" + (int) n[1], "" + (int) n[2], c1);
nString[1] = "" + (int) n[0];
nString[2] = "" + (int) n[3];
break;
case 4:
nString[0] = calString2("" + (int) n[1], "" + (int) n[3], c1);
nString[1] = "" + (int) n[0];
nString[2] = "" + (int) n[2];
break;
default:
nString[0] = calString2("" + (int) n[2], "" + (int) n[3], c1);
nString[1] = "" + (int) n[0];
nString[2] = "" + (int) n[1];
}
if ((c2 / 3 > c1 / 3 && (t2 != 2 || c2 / 3 == c3 / 3))
|| ((c3 / 3 > c1 / 3 + c2 / 3) && t2 == 2)
|| (c3 == 1 && c1 / 3 == 0)) // 特定情况下加上一个括号*****************************
nString[0] = '(' + nString[0] + ')';
switch (t2) {
case 0:
nString[0] = calString2(nString[0], "" + nString[1], c2);
nString[1] = nString[2];
break;
case 1:
nString[0] = calString2(nString[0], nString[2], c2);
break;
default:
nString[3] = nString[0];
nString[0] = calString2(nString[1], nString[2], c2);
nString[1] = nString[3];
}
if (c3 / 3 > c2 / 3 || (c3 == 2 && nString[0].indexOf('+') >= 0)) // 特定情况下加上一个括号*****************************
nString[0] = '(' + nString[0] + ')';
return calString2(nString[0], nString[1], c3);
}
/** calString(),根据符号输出一部运算表达式 */
private String calString2(String n1, String n2, int c) {
switch (c) {
case 0:
return n1 + '+' + n2;
case 1:
return n1 + '-' + n2;
case 2:
return n2 + '-' + n1;
case 3:
return n1 + '*' + n2;
case 4:
return n1 + '/' + n2;
default:
return n2 + '/' + n1;
}
}
}