Java Syntax

Scanner

Syntax Description Library
Scanner scan = new Scanner(System.in);
String s = scan.next();
convert next string to int and return it
store next string to s
 import java.util.*;

Random

Syntax Description Library
Random rnd = new Random();
int i = rnd.nextInt(int n));
Generate a random integer in the range from 0 to n-1  import java.util.Random;

String → String or String[]

Syntax Description Library
str.substring(i,j) return substring of str
str1.equals(str2) check if str1 and str2 are the same (string)
str.split(“delimiter“) split a string by delimiter and return an array of string 
str = “ABC CBA”;
String[] splited = str.split(“\\s+”);    (Delimiter is space)
str.toLowerCase() it returns the String, converted to lowercase.
String.format(“%s %d”, str, num); it returns a string formatted in the following syntax.

String → Char or Char[]

Syntax Description Library
str.charAt(i) find char at i in a string
str.toCharArray() convert str to char array

String → int

Syntax Description Library
scanner.nextInt() convert next string to int and return it
Integer.parseInt(str) convert string to integer

int → String

Syntax Description Library
Integer.toString(int) convert integer to a string

Char

Syntax Description Library
Character.toLowerCase(char) Convert capital letter to lower case letter  import java.lang.*;
char charC = ‘A’;
char charL = Character.toLowerCase(charC);
System.out.println(charL);
Result:
a

Char or Char[] → String

Syntax Description Library
String.valueOf(char) convert char or char array to a string

Char → int

Syntax Description Library
Character.getNumericValue(char) convert char to integer

Integer

Function Description Library
Integer.MAX_VALUE return 2147483647
Integer.MIN_VALUE return -2147483648
Math.abs(num) return absolute value of integer num  java.math.*;
Math.max(x, y) return max value among x and y  java.math.*;
Math.pow(x, y) return value of x raised to the power of y in double  java.math*;

Double → Integer

(int)double convert double to integer

Loop Break

Syntax Description
outerloop:
for(){
   for(){
      break outerloop;
   }
}
break till outerloop