package com.yunsuanfu;
public class yunsuanfu {
/**
* Alt+/ 快捷键能够帮助快速的写代码
* 按住ctrl+鼠标左键可以对应到对应的变量 方法或者其他类
* @param args
*/
public static void main(String[] args) {
//加法
int c = add(7,2);
System.out.println(c);
//减法
float d = substract(100.2f,50.1f);
System.out.println(d);
//乘法
yunsuanfu yy = new yunsuanfu();//记住,由于乘法函数没有定义为静态,故我们需要new一个小写字母的类的实体对象。
int e = yy.cheng(6, 7);
System.out.println(e);
//除法
int f = yy.divide(10,3);//注意,除法中,整型除法和浮点型除法是不一样的
System.out.println("除法:"+f);//注意,这里的+不能省略,意思是字母串与数字(自动)合成一个字符串
//除法-浮点型
float h = yy.divide(10.0f, 3.0f);
System.out.println(h);//print后面加ln意思是换行
//求余
long g = yy.mod(10, 3);
System.out.println(g);
}
/**
* 两个整数相加
* @param a
* @param b
* @return
*/
public static int add(int a,int b)
{
int c = a+b;
return c;
}
/**
* 减法
*/
public static float substract(float a,float b){
float c = a-b;
return c;
}
/**
* 乘法
*/
public int cheng(int a,int b){
int c = a*b;
return c;
}
/**
* 除法
*/
public int divide(int a,int b){
//float c = a/b;
return a/b;
}
/**
* 除法 浮点型
* 对于同一个原理,比如计算除法,不同的数据类型的可以取同一个参数名
*/
public float divide(float a,float b){
return a/b;
}
/**
* 求余
*/
public long mod(long a,long b){
return a%b;
}
}
1.加减乘除运算符中,需要注意的有这几点:
1>对于在主函数里面没有定义为静态或者动态的,可以新建一个new 小写字母的类的实体对象。
2>除法运算中,浮点型和整形的运算是有区别的,前者后面会保留小数,后者只有整数。
3>在打印函数里面,如果要输出一下前置的字符串,需要加个+,这个意思是表明将两个类型转换成字符串输出。
4>对于进行同一个操纵,比如除法,不同数据类型的可以使用同一个函数名。