Category Archives: Java Programs

Java Programs

Java Program to Reverse Given Number

Java Programs to Reverse Given Number

In this tutorial, we will learn to create a Java program that will reverse Given Number using Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.
  • While loop in Java programming.
  • Conditional Statements in Java programming.
  • Arithmetic operations in Java Programming.

Program to reverse any number:-

In this program, we will, first, declare the variables for the program. Then we will assign the values to the variables. Now we will use the while loop to reverse the number using the arithmetic expression. At last, we will print the output to the user.

With the help of this program, we can reverse any Number.

Algorithm:-

Program to reverse any number:-

Output:-

In the above program, we have first initialized the required variable.

  • n = it will hold the integer value.
  • rv = it will hold the integer value.

Input message for the user for the integer value.

Program Logic Code.

Printing output reverses any Number.

Java Program to Print Table of any Number

Java Program to Print Table of any Number

In this tutorial, we will learn to create a Java program that will print a Table of any Number using Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.
  • Conditional Statements in Java programming.
  • Arithmetic operations in Java Programming.

Program to Print Table of any number:- 

In today’s program, we will take input in number format. Secondly, we will print a Table of any number with the help of a small program. The numbers are the most useful terminology in any programming language. For number/arithmetic manipulation in Java programming, there are many predefined functions available.

With the help of this program, we can take input and print the Table of any Number.

Algorithm:-

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • no = it will hold the input number value from the user.
  • i  = it will hold the integer value.

Taking input numbers from the user.

Calculating the table of given numbers using a for loop.

Java Program to Find Factorial of a Number

Java Program to Find Factorial of a Number

In this tutorial, we will learn to create a Java program that will Find Factorial of a Number using Java programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.
  • Conditional Statements in Java programming.
  • Arithmetic operations in Java Programming.

What is factorial?

The factorial means the product of the input number and its below integer value up to 1.

Algorithm:-

Program to Calculate Factorial:-

In today’s tutorial, we will learn to create a program that will find the factorial of a number. First, we will take a number in input from the user. Then we will find the factorial using the for-loop. At last, we will print the factorial of the given number to the user.

Program Code:

Output:-

In the above program, we have first initialized the required variable.

  • no = it will hold the integer value.
  • i = it will hold the integer value.
  • factorial = it will hold the integer value.
Defining the input for the program.
Finding the factorial.

Java Program to Check Whether a Number is Even or Odd

Java Program to Check Whether a Number is Even or Odd

In this tutorial, we will learn to create a Java program that will Check Whether a Number is Even or Odd using Java programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.
  • Conditional Statements in Java programming.
  • Arithmetic operations in Java Programming.

What is an even and odd number?

Even numbers are those numbers that are completely divisible by 2. which means the reminder should be zero. And odd numbers are those numbers that cannot be completely divisible by 2.

Algorithm:-

Program Description:-

In this program, First, we will take an input number from the user. And then we will use it in the program with conditional statements to find whether the number is even or odd. At last, we will print the output number as even or odd.

With the help of this program, we can Check Even and Odd numbers.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • no = it will hold the integer value.

Input number from the user.

Checking if even number.

Printing the even and odd number.

Java Program to Compute Quotient and Remainder

Java Program to Compute Quotient and Remainder

In this tutorial, we will learn to create a Java program that will Compute the Quotient and the Remainder in Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java Programming.

What are Quotient and Remainder?

In the divide operation, the remaining part in the operation is a remainder. The answer part we get after the operation is a quotient.

Algorithm:-

Program to Find Quotient and Remainder:-

In this program, we will first, declare the variables. Then we will assign the values to those variables. Now we will use the arithmetic expression to solve the problem. Finally at last, we will Print the answer.

With the help of this program, we can take input and Find Quotient and Remainder.

Program to Find Quotient and Remainder:-

Output:-

In the above program, we have first initialized the required variable.

  • divisor = it will hold the input number value from the user.
  • dividend= it will hold the input number value from the user.
  • qtnt = it will hold the integer value of the Quotient.
  • rmdr = it will hold the integer value of the Remainder.

Declaring the divisor and dividend from the user.

Calculating the quotient and the remainder.

Printing the output.

Java Program to Find ASCII Value of a character

Java program to Find ASCII Value of a Character

In this tutorial, we will learn to create a Java program that will find the ASCII Value of a Character in Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java Programming.

Program to Find ASCII Value of a Character:-

American Standard Code For Information Interchange stands for ASCII. The ASCII is an encoded format. In Java programming, we can take the input from the user in character format. In today’s program, we will take input in character format. Secondly, we will find the ASCII Value of a Character in the input with the help of a small program.

Algorithm:-

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • c = it will hold the character value from the user.

Taking input characters from the user for the program.

Finding the ASCII value of the character from the code

Printing the ASCII value of the character.

Java Program to Multiply two Floating Point Numbers

Java Program to Multiply two Floating-Point Numbers

In this tutorial, we will learn to create a program that will multiply two Floating-Point Numbers in programming.

Prerequisites:-

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java Programming.

Program Description:- 

As we all know, the integer, float, or double value in Java. First, we will take the input from the user in integer format. Secondly, we will multiply the numbers with the help of the arithmetic operator “*”. The numbers are the most useful terminology in any programming language.

With the help of this program, we can take input and Multiply Two Numbers.

Algorithm to multiply the numbers:-

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • fno = it will hold the input number float value from the user.
  • sno = it will hold the input number float value from the user.
  • multiply = it will hold the multiply value of the two numbers.

Taking input numbers from the user.

Calculating the multiply of two numbers.

Printing the output.

Java Program to Add Two Integer Number

Java Program to Add Two Integer Number

In this tutorial, we will learn to create a Java program that will Add Two Integer Numbers in Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java Programming.

Program to Add Two Numbers:- 

In this tutorial, we will create a program that will add the two numbers using an addition operator. We will first take two numbers in input, and then we will add them and store the value in the third variable. At last, we will print the addition to the user.

With the help of this program, we can take input and Add Two Numbers.

Algorithm:-

Program code to Add Two Integer Number:-

Output:-

In the above program, we have first initialized the required variable.

  • fno = it will hold the input number value from the user.
  • sno = it will hold the input number value from the user.
  • sum = it will hold the sum value of the numbers.

Taking input numbers from the user.

Calculating the sum of two numbers.

Printing the output sum of two numbers.

Java Program to Add Two Numbers

Java Program to Add Two Numbers

In this tutorial, we will learn to create a Java program that will Add Two Numbers in Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java Programming.

What is addition?

The addition in mathematics is the sum of two numbers. The arithmetic operations are done using the arithmetic operators. These operators are used between two arithmetic operands or between two numbers.

Program to Add Two Numbers:- 

In this tutorial, we will create a program that will add the two numbers using an addition operator. We will first take two numbers in input, and then we will add them and store the value in the third variable.

As we all know, the integer, float, or double data types in java. In programming, we can take the input from the user in numbers format. In today’s program, we will take input in number format. Secondly, we will add the number with the help of a small program. The numbers are the most useful terminology in any programming language. For number/arithmetic manipulation, there are many predefined functions available.

With the help of this program, we can take input and Add Two Numbers.

Algorithm to add the numbers:-

Program to Add Two Numbers:-

 

Output:-

In the above program, we have first initialized the required variable.

  • fno = it will hold the input number value from the user.
  • sno = it will hold the input number value from the user.
  • sum = it will hold the sum value of the numbers.

Taking input numbers from the user.

Calculating the sum of two numbers.

Printing the output sum of two numbers.

Java Program to Get User Input and Print on Screen

Java Program to Get User Input and Print on Screen

In this tutorial, we will learn to create a Java program that will get user input and print on screen in Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.

What is a data type?

A data type, in every programming language, specifies which type of value a variable is going to hold in the program. i.e. integer, character, float, double.

Algorithm:-

Program Print output to the user.

In this tutorial, First, we will take input from the user in number format using a scanner class object in the program. Then we will store it in a variable in the memory. Then we will print that number to the user using the print function.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • no = it will hold the input integer value from the user.

Importing the scanner in util package for the program.

Taking the input from the user in integer format.

Printing the integer value to the user by print function.

Java Program to Print an Integer

Java Program to Print an Integer

In this tutorial, we will learn to create a Java program that will print an Integer in Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.

What is a data type?

A data type, in every programming language, specifies which type of value a variable is going to hold in the program. i.e. integer, character, float, double.

Algorithm:-

Program Print an Integer.

In this tutorial, First, we will take an integer number input from the user. Secondly, we will print that number to the user using the print function. Let’s take an example below.

With the help of this program, we can print an Integer.

Program to print an integer:-

Output:-

In the above program, we have first initialized the required variable.

  • no = it will hold the input integer value from the user.

Importing the scanner in util package for the program.

Taking the input from the user in integer format.

Printing the integer value to the user by print function.

Java Program to Print Hello World

Java Program to Print Hello World

In this tutorial, we will learn to create a Java program that will Print Hello World in Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.

Printing a message:-

Message passing is a very important feature for object-oriented programming. Here in this program, we will print the message to the user for hello world.

Algorithm to Print Hello World in the output:-

Program to Print Hello World

The string is a collection of characters in Java programming. The string is used for sending messages on the screen. In Java programming, we can take the input from the user in string format. In this program, we will define input in string format. The second will print the string “Hello World” with the help of a small program. The String is the most useful datatype in any programming language. The message passing in any program is very important. It is also a part of the object-oriented programming (OOP’s) concept.

Program to Print Hello World:-

Output:-

In the above program, we have first initialized the required variable.

  • s = it will hold the input string value from the user.

Importing the util package for the program.

Printing the data in the output in the string format.

The Program Code for the main method.