GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — JavaTutorial/src/F012_TheMathClass.java at master · windweb/JavaTutorial Expand file tree/ Copy pathF012_TheMathClass.javaMore file actions 32 lines (24 loc) · 1.53 KB / Copy pathF012_TheMathClass.javaFile metadata and controls32 lines (24 loc) · 1.53 KB 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. |