Syntax:
double atan2(double y,double x)
Parameters:
Here is the detail of parameters:
X -- X co-ordinate in double data type
Y -- Y co-ordinate in double data type
Return
Value:
This method Returns theta from polar coordinate (r, theta)
Example:
public class Test{
public static void main(String args[]){
double x =45.0;
double y =30.0;
TUTORIALS POINT
Simply
Easy
Learning
System.out.println(Math.atan2(x, y));
}
}
This produces the following result:
0.982793723247329
toDegrees()
Description:
The method converts the argument value to degrees.
Syntax:
double toDegrees(double d)
Parameters:
Here is the detail of parameters:
d -- A double data type.
Return
Value:
This method returns a double value.
Example:
public class Test{
public static void main(String args[]){
double x =45.0;
double y =30.0;
System.out.println(Math.toDegrees(x));
System.out.println(Math.toDegrees(y));
}
}
This produces the following result:
2578.3100780887044
1718.8733853924698
toRadians()
Description:
TUTORIALS POINT
Simply
Easy
Learning
The method converts the argument value to radians.
Syntax:
double toRadians(double d)
Parameters:
Here is the detail of parameters:
d -- A double data type.
Return
Value:
This method returns a double value.
Example:
public class Test{
public static void main(String args[]){
double x =45.0;
double y =30.0;
System.out.println(Math.toRadians(x));
System.out.println(Math.toRadians(y));
}
}
This produces the following result:
0.7853981633974483
0.5235987755982988
random()
Description:
The method is used to generate a random number between 0.0 and 1.0. The range is: 0.0 =< Math.random
<
1.0. Different ranges can be achieved by using arithmetic.
Syntax:
staticdouble random()
Parameters:
Here is the detail of parameters:
TUTORIALS POINT
Simply
Easy
Learning
NA
Return
Value:
This method returns a double
Example:
public class Test{
public static void main(String args[]){
System.out.println(Math.random());
System.out.println(Math.random());
}
}
This produces the following result:
0.16763945061451657
0.400551253762343
Note: Above result would vary every time you would call random() method.
What
is
Next?
In the next section, we will be going through the Character class in Java. You will be learning how to use object
Characters and primitive data type char in Java.
TUTORIALS POINT
Simply
Easy
Learning
Java Characters
ormally, when we work with characters, we use primitive data types char.
Example:
char ch ='a';
// Unicode for uppercase Greek omega character
char uniChar ='\u039A';
// an array of chars
char[] charArray ={'a','b','c','d','e'};
However in development, we come across situations where we need to use objects instead of primitive data
types.
Inorder to achieve this, Java provides wrapper class Character for primitive data type char.
The Character class offers a number of useful class (i.e., static) methods for manipulating characters. You can
create a Character object with the Character constructor:
Character ch =newCharacter('a');
The Java compiler will also create a Character object for you under some circumstances. For example, if you
pass a
primitive char into a method that expects an object, the compiler automatically converts the char to a Character
for
you. This feature is called autoboxing or unboxing, if the conversion goes the other way.
Example:
// Here following primitive char 'a'
// is boxed into the Character object ch
Character ch ='a';
// Here primitive 'x' is boxed for method test,
// return is unboxed to char 'c'
char c = test('x');
Escape
Sequences:
A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler.
CHAPTER
12
TUTORIALS POINT
Simply
Easy
Learning
The newline character (\n) has been used frequently in this tutorial in System.out.println() statements to advance
to
the next line after the string is printed.
Following table shows the Java escape sequences:
Escape Sequence Description
\t Inserts a tab in the text at this point.
\b Inserts a backspace in the text at this point.
\n Inserts a newline in the text at this point.
\r Inserts a carriage return in the text at this point.
\f Inserts a form feed in the text at this point.
\' Inserts a single quote character in the text at this point.
\" Inserts a double quote character in the text at this point.
\\ Inserts a backslash character in the text at this point.
When an escape sequence is encountered in a print statement, the compiler interprets it accordingly.
Example:
If you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes:
public class Test{
public static void main(String args[]){
System.out.println("She said \"Hello!\" to me.");
}
}
This would produce the following result:
She said "Hello!" to me.
Character
Methods:
Here is the list of the important instance methods that all the subclasses of the Character class implement:
SN Methods with Description
1
isLetter()
Determines whether the specified char value is a letter.
2
isDigit()
Determines whether the specified char value is a digit.
3
isWhitespace()
Determines whether the specified char value is white space.
4
isUpperCase()
Determines whether the specified char value is uppercase.
TUTORIALS POINT
Simply
Easy
Learning
5
isLowerCase()
Determines whether the specified char value is lowercase.
6
toUpperCase()
Returns the uppercase form of the specified char value.
7
toLowerCase()
Returns the lowercase form of the specified char value.
8
toString()
Returns a String object representing the specified character valuethat is, a one-character string.
For a complete list of methods, please refer to the java.lang.Character API specification.
isLetter()
Description:
The method determines whether the specified char value is a letter.
Syntax:
boolean isLetter(char ch)
Parameters:
Here is the detail of parameters:
ch -- Primitive character type
Return
Value:
This method Returns true if passed character is really a character.
Example:
public class Test{
public static void main(String args[]){
System.out.println(Character.isLetter('c'));
System.out.println(Character.isLetter('5'));
}
}
This produces the following result:
true
false
TUTORIALS POINT
Simply
Easy
Learning
isDigit()
Description:
The method determines whether the specified char value is a digit.
Syntax:
boolean isDigit(char ch)
Parameters:
Here is the detail of parameters:
ch -- Primitive character type
Return
Value:
This method Returns true if passed character is really a digit.
Example:
public class Test{
public static void main(String args[]){
System.out.println(Character.isDigit('c'));
System.out.println(Character.isDigit('5'));
}
}
This produces the following result:
false
true
isWhitespace()
Description:
The method determines whether the specified char value is a white space, which includes space, tab or
new
line.
Syntax:
boolean isWhitespace(char ch)
TUTORIALS POINT
Simply
Easy
Learning
Parameters:
Here is the detail of parameters:
ch -- Primitive character type
Return
Value:
This method Returns true if passed character is really a white space.
Example:
public class Test{
public static void main(String args[]){
System.out.println(Character.isWhitespace('c'));
System.out.println(Character.isWhitespace(' '));
System.out.println(Character.isWhitespace('\n'));
System.out.println(Character.isWhitespace('\t'));
}
}
This produces the following result:
false
true