基本算术运算符与模运算符

2019-04-13 12:49发布

public class Test {
 
 public static void main(String[] args) {
  //声明两个int类型的变量
  int i1=7;
  int i2=2;
  System.out.println("基本运算符演示,整数类型");
  System.out.println("i1="+i1+"i2="+i2);
  System.out.println("i1+i2="+(i1+i2));
  System.out.println("i1-i2="+(i1-i2));
  System.out.println("i1*i2="+(i1*i2));
  System.out.println("i1/i2="+(i1/i2));
  
  
  //声明两个double类型的变量
  double d1=8.0;
  double d2=2.5;
  System.out.println("浮点类型转换");
  System.out.println("d1="+d1+"d2="+d2);
  System.out.println("d1+d2="+(d1+d2));
  System.out.println("d1-d2="+(d1-d2));
  System.out.println("d1*d2="+(d1*d2));
  System.out.println("d1/d2="+(d1/d2));
 }
}         public class Test2 {
 
 public static void main(String[] args) {
  
  int i1=5;
  int i2=2;
  
  double d1=2.4;
  double d2=1.1;
  
  System.out.println("int i1="+i1+"i2="+i2);
  System.out.println("double d1="+d1+"d2="+d2);
  
  System.out.println("i1%i2="+(i1%i2));
  System.out.println("i1%d1="+(i1%d1));
  System.out.println("d1%d2="+(d1%d2));
  System.out.println("d1%d2="+(d1%i2));
 } }