java除法怎么写

1. 用java for 怎么写九九除法表 就这一个不回了 package easy;
import java.util.Scanner;
public class NineTable {
public static void main(String[] args) {
NineTable n=new NineTable();
n.check();
}
public boolean check(){
System.out.println("请输入:");
Scanner scanner=new Scanner(System.in);
int[] arr=new int[8];
//输入数据
for(int i=0;i<=arr.length;i++){
while(true){
if((i+1)%3!=0){
arr[i]=scanner.nextInt();
}else{
arr[i]=scanner.nextInt();
System.out.println();
}
}
}
return true;
}
}
2. java中 BigDecimal的类型的除法 package cn.itcast_02;
import java.math.BigDecimal;
/*
* 构造方法:
* public BigDecimal(String val):
*
* 金融相关的东西(例:银行钱的小数 , 商品价格小数 , 实验小数)
*
* 成员方法:
* public BigDecimal add(BigDecimal augend):加
* public BigDecimal subtract(BigDecimal subtrahend):减
* public BigDecimal multiply(BigDecimal multiplicand):乘
* public BigDecimal divide(BigDecimal divisor):除
* public BigDecimal divide(BigDecimal divisor,int scale,int roundingMode):商 , 几位小数 , 如何舍取 。
*
*/
public class BigDecimalDemo {
【java除法怎么写】public static void main(String[] args) {
System.out.println(0.09 + 0.01);
System.out.println(1.0 - 0.32);
System.out.println(1.015 * 100);
System.out.println(1.301 / 100);
// public BigDecimal add(BigDecimal augend):加
BigDecimal bd1 = new BigDecimal("0.09");
BigDecimal bd2 = new BigDecimal("0.01");
System.out.println("add:" + bd1.add(bd2));
System.out.println("----------------------");
// public BigDecimal subtract(BigDecimal subtrahend):减
BigDecimal bd3 = new BigDecimal("1.0");
BigDecimal bd4 = new BigDecimal("0.32");
System.out.println("subtract:" + bd3.subtract(bd4));
System.out.println("----------------------");
// public BigDecimal multiply(BigDecimal multiplicand):乘
BigDecimal bd5 = new BigDecimal("1.015");
BigDecimal bd6 = new BigDecimal("100");
System.out.println("multiply:" + bd5.multiply(bd6));
System.out.println("----------------------");
// public BigDecimal divide(BigDecimal divisor):除
BigDecimal bd7 = new BigDecimal("1.301");
BigDecimal bd8 = new BigDecimal("100");
System.out.println("divide:" + bd7.divide(bd8));
System.out.println("divide:" + bd7.divide(bd8,3,BigDecimal.ROUND_HALF_UP));
System.out.println("divide:" + bd7.divide(bd8,9,BigDecimal.ROUND_HALF_UP));
}
}
3. java 两个数组的除法 public static void main(String[] args) {
int[] a = {1,2,3,23,56,45,88};
int[] b = {3,2,3,23,56,45,88};
double[] c = new double[a.length];
for(int i = 0;iif(b[i] == 0){
return;
}
double s = (double)a[i]/b[i];
// DecimalFormat df = new DecimalFormat("#.00");
// System.out.println(df.format(s));
// c[i] = Double.valueOf(df.format(s));
// System.out.println(c[i]);
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
System.out.println(nf.format(s));
c[i] = Double.parseDouble(nf.format(s));
}
}

java除法怎么写

文章插图