不晓得math相关函数,用分支输出
向下取整:Math.floor(3.5)=3
四舍五入取整:Math.round(3.5)=4
向上取整:Math.ceil(3.1)=4
取绝对值:Math.abs(-3.5)=3.5
取余数:6%4=2
求模运算:6/4=1
Math.rint() :返回最接近参数的整数,如果有两个数同时接近,则返回偶数的那一个
原文链接:https://blog.csdn.net/he_zhen_/article/details/88576130
Math.sqrt()开平方
1015 计算时间间隔Java的输入和c语言不一样,不能修改输入的格式,所以用nextLine()
利用String类的方法去定义字符串,然后再使用split去分隔字符串,在其中特定位置加入特定的字符
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
String s1,s2;
s1=input.nextLine();
String a1[]=s1.split(":");
int x1=Integer.parseInt(a1[0]);
int y1=Integer.parseInt(a1[1]);
int z1=Integer.parseInt(a1[2]);
s2=input.nextLine();
String a2[]=s2.split(":");
int x2=Integer.parseInt(a2[0]);
int y2=Integer.parseInt(a2[1]);
int z2=Integer.parseInt(a2[2]);
int sum=(z2-z1)+(y2-y1)*60+(x2-x1)*3600;
System.out.println(sum);
}
}
原代码链接:https://blog.csdn.net/weixin_43823808/article/details/102924974
了解了一下nextLine()和next():
nextLine()方法返回的是Enter键之前的所有字符,它是可以得到带空格的字符串的。
next()会自动消去有效字符前的空格,只返回输入的字符,不能得到带空格的字符串。



