//1.number 2.enum 3.format float
//学习了 整数和FLOAT的 计算 ,枚举的使用 。 小数的格式化
package com.linson;
import java.text.DecimalFormat;
enum enum_op
{
add,minus,time,divide
}
public class HelloWord
{
public static void main(String[] args)
{
System.out.println("hello world");
HelloWord mMainHelloWord=new HelloWord();
enum_op[] allOps=enum_op.values();
int a=2,b=3;
for(int i=0;i<allOps.length;i++)
{
System.out.println(mMainHelloWord.NumberCaculate(a, b, allOps[i]));
System.out.println(mMainHelloWord.NumberCaculate_float(a, b, allOps[i]));
}
//format float
DecimalFormat tempDF=new DecimalFormat();
tempDF.applyPattern("0.00");
float tempret=mMainHelloWord.NumberCaculate_float(16, 3, enum_op.divide);
System.out.println(tempDF.format(tempret));
}
public int NumberCaculate(int a,int b,enum_op operate)
{
int ret=0;
switch (operate)
{
case add:
ret=a+b;
break;
case minus:
ret=a-b;
break;
case time:
ret=a*b;
break;
case divide:
ret=a/b;
break;
default:
break;
}
return ret;
}
public float NumberCaculate_float(float a,float b,enum_op operate)
{
float ret=0;
switch (operate)
{
case add:
ret=a+b;
break;
case minus:
ret=a-b;
break;
case time:
ret=a*b;
break;
case divide:
ret=a/b;
break;
default:
break;
}
return ret;
}
}