"四舍五入"package com.itheiam;
public class DayFive16 {
public static void main(String[] args) {
double num = 5.45;
int i = si(num);
System.out.println(num + "四舍五入后的值是:" + i);
}
public static int si(double num){
int a = (int)(num*10%10);
System.out.println(a);
if(a>4){
return (int)num+1;
}else{
return (int)num;
}
}
}"取绝对值"package com.itheiam;
public class DayFive15 {
public static void main(String[] args) {
double num = jue(-100);
System.out.println("绝对值是:"+ num);
}
public static double jue(double num){
if(num<0){
return -num;
}else{
return num;
}
}
}
"9*9乘法算数表"package com.itheiam;
import java.util.Scanner;
public class DayFive14 {
public static void main(String[] args) {
cheng();
}
public static void cheng() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个[1-9]的整数");
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(i + "*" + j + "=" + (i * j)+"\t");
}System.out.println();
}
}
}
|
|