题解 | #四舍五入#

四舍五入

https://www.nowcoder.com/practice/cae89de6292b4084acb93659353260e0

import java.util.Scanner;

public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);double d= scanner.nextDouble();

    //write your code here......
    String str = String.valueOf(d);
    int integer = Integer.parseInt(str.split("\\.")[0]);
    int i =str.indexOf(".");  //2
    int j =str.indexOf(".") + 1;  //3
    String index = str.substring(i+1,j+1);
    int decimal = Integer.parseInt(index);
    if(decimal>=5) {
        integer +=1;
    }

    System.out.println(integer);
}

}

全部评论

相关推荐

站队站对牛:兄弟 你这是四年就当大一过了吧 也许你校园卡 赚了有五位数了
点赞 评论 收藏
分享
头像
09-01 09:00
已编辑
四川旅游学院 运营
牛客55195891...:主要是专业不好,别的没毛病
牛客解忧铺
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务