This is a Java Program to Convert Integer Values into Byte, Character, Float.
Enter any integer as input. After that we convert the given integer into byte and char by type casting (Explicit casting) but we can directly convert int value to float value as java itself performs this type of type casting (Implicit casting).
Here is the source code of the Java Program to Convert Integer Values into Byte, Character, Float. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
import java.util.Scanner;
public class Integer_Conversion
{
public static void main(String[] args)
{
int a;
byte b;
char c;
float d;
Scanner s = new Scanner(System.in);
System.out.print("Enter any integer:");
a = s.nextInt();
b = (byte) a;
System.out.println("Conversion into byte:"+b);
c = (char) a;
System.out.println("Conversion into char:"+c);
d = a;
System.out.println("Conversion into float:"+d);
}
}
Output:
$ javac Integer_Conversion.java $ java Integer_Conversion Enter any integer:97 Conversion into byte:97 Conversion into char:a Conversion into float:97.0
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Practice Programming MCQs
- Practice BCA MCQs
- Check Java Books
- Apply for Computer Science Internship
- Practice Information Technology MCQs