Java计算n的二进制位上有几个1,分别在什么位置 public List<Integer> getBinOneCount(int n){ List<Integer> ar = new ArrayList<>(); int index=0; while(n>0){ int x=n&1<<index; if(x!=0){ ar.add(index+1);
使用java计算数组方差和标准差 觉得有用的话,欢迎一起讨论相互学习~Follow Me 首先给出方差和标准差的计算公式 代码 public class Cal_sta { double Sum(double[] data) { double sum = 0; for (int i = 0; i < data.length; i++) sum = sum + data[i]; return sum; } double Mean(double[] data) { double mean = 0;
Java 计算加几个月之后的时间 public static Date getAfterMonth(String inputDate,int number) { Calendar c = Calendar.getInstance();//获得一个日历的实例 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try{ date = sdf.parse(inputDate);//初始日期
题目链接:1325: Distance Description There is a battle field. It is a square with the side length 100 miles, and unfortunately we have two comrades who get hurt still in the battle field. They are in different positions. You have to save them. Now I give
import java.util.Scanner; public class Zuheshu { //计算m阶乘 public static int Fun(int m){ int sum=0; if( m < 0 ) System.out.println("input error,please input integer(bigger than 1):"); else if( m == 1 || m == 0 ) return 1; else