当前位置:网站首页>Hj7 take approximate value
Hj7 take approximate value
2022-07-25 22:58:00 【Min Min, chengxuyuan】
describe
Write a program , Accept a positive floating point number , Output the approximate integer value of this value . If the value after the decimal point is greater than or equal to 0.5 , Rounding up ; Less than 0.5 , Then round down .
Data range : Make sure that the number entered is in 32 Bit floating point number range
Input description :
Enter a positive floating point number
Output description :
Output the approximate integer value of this value
Example 1
Input :5.5
Output :6
explain :0.5>=0.5, therefore 5.5 Need to round up to 6
Example 2
Input :2.499
Output :2
explain :0.499<0.5,2.499 Round down to 2
Algorithm implementation
/**
Ideas :
1. establish Scanner Class to receive input statements , Enter positive floating point type , And output the corresponding results ;
2. Can force conversion int type
3. You can take the rest
4. Can function :
*/
import java.util.Scanner;
/**
*Author: Xiang min
*Date:2020/07/22 14:36
*/
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext())
{
float input = scanner.nextFloat();
System.out.println(floatToInt(input));
}
scanner.close();
}
// Integral function
public static int floatToInt(float f)
{
// Take the remainder and round it
return (int)(f*10 + 5)/10;
}
};边栏推荐
- QT operation to solve large amount of duplicate data
- [training day13] backpack [dynamic planning] [greed]
- Network Security Learning (XIII) data link layer
- The difference between abstract classes and interface interfaces
- The difference between abstract classes and interfaces
- Mysql数据类型
- Node.js operation database
- Two methods of printing strings in reverse order in C language
- What are the differences between FileInputStream and bufferedinputstream?
- 【MySQL提权】UDF提权(附带大马)
猜你喜欢

Tree view model example of QT

Deploy flash based websites using Google cloud

CUDA environment construction

1000 okaleido tiger launched binance NFT, triggering a rush to buy

Stack and stack class

We media people must have four material websites, and don't worry about finding materials anymore

【论文笔记】基于在线预测和规划的机器人动态跟踪抓取方法

Recyclerview computehorizontalscrollextend computehorizontalscrollrange computehorizontalscroll for calculating the sliding distance

内存分页与调优,内核与用户空间

栈与Stack类
随机推荐
Network Security Learning (XV) ARP
Deep recursion, deep search DFS, backtracking, paper cutting learning.
AI首席架构师12-AICA-工业生产过程优化场景下产业落地解析
Session and cookie, token and storage
We media people must have four resource tools, each of which is very practical
技术美术百人计划学习笔记(1)--基础渲染管线
Deploy flash based websites using Google cloud
Panzer_ Jack's personal blog founding day
新媒体运营策略(以小红书为例)帮助你快速掌握爆款创作方法
Review of static routing
ZCMU--5015: 完成任务
JD quick navigation box
Interview question 17.11. word distance ●●
The third programming competition of Wuhan University of technology b- save the kingdom of DAG (topological properties deal with accessibility Statistics)
DOM event binding
内存分页与调优,内核与用户空间
Design of regular expressions
Experiment 1, experiment 2 and Experiment 3 of assembly language and microcomputer principle: branch program design / loop program design / subroutine design
DOM event object
Notification(状态栏通知)详解