Convert int type to char

Java Program to Convert int to char In the above example, we have int type variables num1 and num2. Notice the line, Here, we are using typecasting to covert an int type variable into the char type variable. Note that the int values are treated as ASCII values. Hence, we get P for int value 80 and Q for int value 81. It is because the ASCII value of P and Q are 80 and 81 respectively.

Convert int to double

Convert int to double using Typecasting In the above example, we have int type variables a and b. Notice the line, Here, the int type variable is automatically converted into double. It is because double is a higher data type (data type with larger size) and int is a lower data type (data type with smaller size). Hence, there will be no loss in data while converting… Continue reading Convert int to double

Swap Two Numbers

Swap two numbers using temporary variable Output: In the above program, two numbers 1.20f and 2.45f which are to be swapped are stored in variables: first and second respectively. The variables are printed before swapping using println() to see the results clearly after swapping is done. First, the value of first is stored in variable temporary (temporary = 1.20f). Then, value of second is stored in first (first = 2.45f). And, finally value… Continue reading Swap Two Numbers

Round a Number

Round a Number using format Output In the above program, we’ve used the format() method to print the given floating-point number num to 4 decimal places.  The 4 decimal places are given by the format .4f. This means, print only up to 4 places after the dot (decimal places), and f means to print the floating-point number.

Compute Quotient and Remainder

In this program, you’ll learn to compute quotient and remainder from the given dividend and divisor in Java. Example: Compute Quotient and Remainder Output: In the above program, we have created two variables dividend and divisor. Here, we are calculating the quotient and remainder by dividing 25 by 4. To find the quotient, we have… Continue reading Compute Quotient and Remainder

Multiply two Floating Point Numbers

In this program, you’ll learn to multiply two floating point numbers in Java, store the result and display it on the screen. Example: Multiply Two Floating-Point Numbers Output In the above program, we have two floating-point numbers 1.5f and 2.0f stored in variables first and second respectively. Notice, we have used f after the numbers. This ensures the numbers are float, otherwise they will be assigned… Continue reading Multiply two Floating Point Numbers

Add Two Integers

In this program, you’ll learn to store and add two integer numbers in Java. After addition, the final sum is displayed on the screen. Program to Add Two Integers Output: In this program, two integers 10 and 20 are stored in integer variables first and second respectively. Then, first and second are added using the + operator, and its result is stored in another variable sum. Finally, sum is printed on the… Continue reading Add Two Integers

Hello World

A “Hello, World!” is a simple program that outputs Hello, World! on the screen. Since it’s a very simple program, it’s often used to introduce a new programming language to a newbie. Let’s explore how Java “Hello, World!” program works. Java “Hello, World!” Program Output How Java “Hello, World!” Program Works? // Your First Program In Java,… Continue reading Hello World