GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaTutorial/src/F012_TheMathClass.java at master · windweb/JavaTutorial

Expand file tree

/

F012_TheMathClass.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
32 lines (24 loc) · 1.53 KB
/

F012_TheMathClass.java

Copy path

File metadata and controls

32 lines (24 loc) · 1.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class F012_TheMathClass {
public static void main(String[] args) {
int result = Math.round(1.1F); // Округлить до целого
System.out.println(result); // 1
int result2 = (int)Math.ceil(1.1F); // Округлить вверх
System.out.println(result2); // 2
int result3 = (int)Math.floor(1.1F); // Округлить вниз
System.out.println(result3); // 1
int result4 = (int)Math.max(1, 2); // Максимальное значение
System.out.println(result4); // 2
double result5 = Math.random(); // Случайное число в диапазоне от 0 до 1 с дробной частью
System.out.println(result5); // 0.4368805334217625
double result6 = Math.random() * 100; // Случайное число в диапазоне от 0 до 100 с дробной частью
System.out.println(result6); // 49.123
int result7 = (int) Math.round(Math.random() * 100); // Случайное число в диапазоне от 0 до 100 с округлением до целого
System.out.println(result7); // 49
// но
int result8 = (int) Math.random() * 100; // всегда 0
System.out.println(result8); // всегда = 0
// однако
int result9 = (int) (Math.random() * 100); // Случайное число в диапазоне от 0 до 100 с округлением до целого
System.out.println(result9); // 49
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.