-
Book Overview & Buying
-
Table Of Contents
Java Fundamentals
By :
To convert an int of value of 23 into a long literal, we would need to do what is called type casting:
int num_int = 23; long num_long = (long)num_int;
In the second line, we cast the num_int of the int type to a long literal by using the notation (long)num_int. This is referred to as casting. Casting is the process of converting one data type into another. Although we can cast a long to an int, remember that the number might be outside the int range and some numbers will be truncated if they can't fit into the int.
As is with int, long can also be in octal, hexadecimal, and binary, as shown in the following code:
long num = 117L; long hex_num = 0x75L; long oct_num = 0165L; long bin_num = 0b1110101L;
It's often important to change one type to another. In this exercise, we will convert an integer into a floating point:
Import Scanner and create a public class:
import java.util.Scanner;
public class Main
{
static Scanner sc = new Scanner(System.in);...
Change the font size
Change margin width
Change background colour