From 070d79b807cb52f6e2fbc2dd2342a90b3abe9200 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 14 Oct 2018 06:59:43 +0800 Subject: [PATCH] Java Guide- Added Examples to Built in funcions (#18797) Added examples of Java.IO package and Java.lang packages --- .../english/java/built-in-functions/index.md | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/client/src/guide/english/java/built-in-functions/index.md b/client/src/guide/english/java/built-in-functions/index.md index 883e80a9be..16c3e43e72 100644 --- a/client/src/guide/english/java/built-in-functions/index.md +++ b/client/src/guide/english/java/built-in-functions/index.md @@ -10,4 +10,32 @@ import java.lang.*; import java.io.*; ``` -These comprise functions which make an otherwise long and hard task easier to do. +These comprise functions which make an otherwise long and hard task easier to do. + +Some examples of ```java.lang.* ``` are: + +Generating a random number using Math. In this example a random integer from 1 - 10 +```java +int randomNumber = (int) (Math.random() * 10) + 1; +``` +Usage of primitive types such as double, float, int boolean + +```java +int integerNumber = 1; +double doubleNumber = 0.1d; +float floatNumber = 0.2f; +boolean trueOrFalse = false; +``` + + +Classes in ```java.io.* ``` are mainly used for reading and writing of files with diffrent methods such as Input / output streams and buffered readers/ writers. +And example using a buffered reader is below: + +```java + File file = new File("C:\\Users\\Desktop\\test.txt"); + BufferedReader br = new BufferedReader(new FileReader(file)); + String st; + while ((st = br.readLine()) != null) + System.out.println(st); +``` +