100 basic java programs with explanation and output

100 basic java programs with explanation and output. This website will help you to learn Java programming examples with source code  for beginners to learn  basic Java programming, the best way to learn is to train not only for Java program, but also for 100 or more java program

Abstract class program in java with output

Learn programs like abstract class program in java with output. In this program, you can execute the abstract class program with an example. An abstract class is one that has been declared to be abstract; it may or may not have abstract methods.

abstract class cycle{
abstract void run();
}

class hercules extends cycle{
void run(){System.out.println("drive carefully");}

public static void main(String args[]){
cycle obj = new hercules();
obj.run();
}
}

Drive carefully

Java program to execute continue using inner loop method

A Java program to execute continue using inner loop method. In this program we can execute the inner loop with continue statement. A Java programme that uses the inner loop method to keep running. We may use the continue command to execute the inner loop in this program. In any loop control structure, the continue keyword can be utilised. It forces the loop to jump to the next iteration of the loop right away. Control is instantly given to the update statement when the continue keyword is used in a for loop.

public class Main
{
public static void main(String[] args)
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
if(i==2&&j==2)
{
continue;
}
System.out.println(i+" "+j);
}
}
}
}

3 5
4 1
4 2
4 3
4 4
4 5
5 1
5 2
5 3
5 4
5 5

Java program to execute continue statement

A Java program to execute continue statement. By using this program we can print the execute the continue statement in java. The continue keyword can be used in any loop control structure. It forces the loop to immediately jump to the next iteration of the loop. When the continue keyword is used in a for loop, control is immediately passed to the update statement. The continue keyword is used in a for loop or a while loop to end the current iteration and go on to the next.

public class Main
{
public static void main(String[] args)
{
for(int i=1;i<=10;i++)
{
if(i==5)
{
continue;
}
System.out.println(i);
}
}
}

1
2
3
4
6
7
8
9
10

Fibonacci series program in java using recursion and looping statements

The Fibonacci series program in java using recursion and looping statements. In Java, a Fibonacci Series is a set of numbers where the next number is the sum of the previous two. The Fibonacci series begins with the digits 0 and 1. The Fibonacci numbers play an important role in determining the greatest common divisor of two integers in a computational run-time study. The Wythoff array is an infinite matrix of numbers derived from the Fibonacci sequence in arithmetic.

Unknown fact of fibonacci series

It represents structures and sequences that model physical reality, the Fibonacci sequence emerges in nature. Because it intrinsically models a sort of spiral, we see it in the spiral patterns of certain flowers.

Click here to read more

Fibonacci series program in java using for loop

public class main
{
public static void main(String[] args)
{
int limit = 10;
int last = 0;
int upcoming = 1;
System.out.print("Fibonacci series "+limit+" numbers");
for (int i = 1; i <= limit; ++i)
{
System.out.print(last+" ");
int sum = last + upcoming;
last = upcoming;
upcoming = sum;
}

}

}

Output:

Fibonacci series 5 numbers0 1 1 2 3

What is for loop in java programming

A for loop is a repetition control structure that allows you to design a loop that must be repeated a certain number of times quickly. When you know how many times a task will be repeated, a for loop comes in handy.

Fibonacci series program in java using while loop

public class Main
{
public static void main(String[] args)
{
int limit = 10, last = 0, upcoming = 1;
System.out.print("Fibonacci Series of "+limit+" numbers");
int i=1;
while(i <= limit)
{
System.out.print(last+" ");
int sum = last + upcoming;
last = upcoming;
upcoming = sum;
i++;
}
}
}

Output:

Fibonacci Series of 10 numbers

0 1 1 2 3 5 8 13 21 34 

What is while loop in java programming

The condition is assessed first in a while loop, and if it returns true, the statements inside the while loop are executed. This process is repeated until the condition returns false. When the condition returns false, the control exits the while loop and moves on to the next sentence in the program.

Fibonacci series program in java using recursion method

public class Main
{
public static int fibonacciRecursion(int n)
{
if(n == 0){
return 0;
}
if(n == 1 || n == 2)
{
return 1;
}
return fibonacciRecursion(n-2) + fibonacciRecursion(n-1);
}
public static void main(String args[])
{
int limit = 10;
System.out.print("Fibonacci Series of "+limit+" numbers: ");
for(int i = 0; i < limit; i++){
System.out.print(fibonacciRecursion(i) +" ");
}
}
}

Output:

Fibonacci Series of 10 numbers: 0 1 1 2 3 5 8 13 21 34

What is recursion in java programming

The technique of repeating objects in a self-similar manner is known as recursion. Recursion is a feature of the C programming language, which allows a function to call itself. However, when employing recursion, programmers must ensure that the function has an exit condition, or else it would enter an indefinite loop.

Java program to find the length of the array and string a single program

A simple java program to find the length of the array and string a single program. Using this program we can calculate array and string in the array in java.  The array length in Java refers to the maximum number of elements that an array can hold.

The length of an array cannot be determined using any predefined method. The array attribute length in Java can be used to determine the array length.

public class Main
{
public static void main(String[] args)
{

int[] array = new int[4];
System.out.println("The size of the array is " + array.length);
String str = "Inlarn.com";
System.out.println("The size of the String is "+ str.length());
}
}

Output:

The size of the array is 4
The size of the String is 10

What is length() in java

The length() method of the String class is a static method. The length() method returns the length of a string object or the number of characters it contains. This function is used by the String class because the length of a string can be changed using various operations on an object.

What is array length in java

The array length in Java refers to the maximum number of elements that an array can hold. The length of an array cannot be determined using any predefined method. The array attribute length in Java can be used to determine the array length.

Difference between size and length in array in java

size() is a method defined in the java. util. Collection package, which is inherited by all data structures in the standard library. length is a field on any array (arrays are objects, although you don’t generally see the class), and length() is a java function.

Java program to pay and calculate mortgage, loan and insurance payment

Java program to pay and calculate mortgage, loan, and insurance payment. Your mortgage payment is the method by which you repay your home loan.

This is usually a once-a-month payment that helps you pay off your mortgage gradually. It will also include payments for your lender’s interest, insurance, and taxes.

import java.util.Scanner;
class Main
{
public static void main(String arg[])
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter the principal money ");
double principal = scan.nextDouble();
System.out.print("Enter rate of interest per principal amount");
double rate = scan.nextDouble();
rate =( rate/100)/12;
System.out.print("Enter duration of the loan amount");
int time = scan.nextInt();
time = time * 12;
double p= (principal * rate) / (1 - Math.pow(1 + rate, -time));
System.out.println("Your payment is" + p);
}
}

Output:

Enter the principal money 1500000
Enter the rate of interest per principal amount7
Enter the duration of the loan amount20
Your payment is11629.484034283096

What is the difference between nextin and nextdouble in java

NextDouble

The Java Scanner class has a method called nextDouble() that scans the next token of the input as a double. The scanner passes the input that matched if the translation was successful.

nextLine()

The java. util. nextLine() function is used to get the next line in a string. The Scanner class searches for a line separator delimiter starting at the current location. The String from the current place to the end of the line is returned by this method.

What is mortgage and how its differ from pledge

Mortgage

The principal is the amount you borrow with your mortgage. Part of your monthly payment will be used to pay down the main, or mortgage debt, and the rest will be used to pay interest on the loan. The lender charges you interest for the lending you money.

Pledge

In the case of mobile properties, a pledge is utilised, and in the case of immovable goods, a mortgage is used. The items are kept with the lender in the case of a pledge, whereas mortgaged properties are kept with the borrower.

How to calculate mortgage in calculator

If you wish to calculate your monthly mortgage payment by hand, you’ll need the monthly interest rate, which you can get by dividing the annual interest rate by 12 months (the number of months in a year). The monthly interest rate, for example, would be 0.33 percent (0.04/12 = 0.0033) if the yearly interest rate is 4%. 01.

What is the rate of interest and how to calculate it

rate=(rate/100)/12

The interest rate is the percentage of the principal that a lender charges for the use of assets. The annual percentage rate (APR) is used to express the interest rate on a yearly basis (APR). Cash, consumer goods, or significant assets like a vehicle or a building could be used as collateral.

Transpose matrix java program in java in a single matrix

Transpose matrix java program in java in a single matrix. A matrix is a rectangular array of numbers that are arranged in rows and columns. The numbers are referred to as the matrix’s elements or entries. Engineering, physics, economics, biology, and statistics, as well as various disciplines of mathematics, all use matrices.

import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int i,j,row,col,temp;
System.out.println("Enter the number of rows");
row = sc.nextInt();
System.out.println("Enter the number of columns");
col = sc.nextInt();
int[][] mat = new int[row][col];
System.out.println("Enter the elements of the matrix") ;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
mat[i][j] = sc.nextInt();
}
}
System.out.println("The elements of the matrix") ;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
System.out.print(mat[i][j]+"\t");
}
System.out.println("");
}
for(i=0;i<row;i++)
{
for(j=0;j<i;j++)
{
temp = mat[i][j];
mat[i][j] = mat[j][i];
mat[j][i] = temp;
}
}
System.out.println("The transpose of the matrix is ") ;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
System.out.print(mat[i][j]+"\t");
}
System.out.println("");
}
}
}

Output:

Enter the number of rows
2
Enter the number of columns
2
Enter the elements of the matrix
45
67
78
34
The elements of the matrix
45 67
78 34
The transpose of the matrix is
45 78
67 34

Uses of matrices in computer programming

Matrices can be used to write and work with many linear equations (a system of linear equations) in a compact manner. When it comes to linear transformations, often known as linear maps, matrices and matrix multiplication show their true colors. They are used to create graphs, calculate statistics, and conduct scientific studies and research in a variety of subjects. Matrices can also be used to represent real-world information such as population, infant mortality rate, and so on. For charting surveys, these are the finest representation methods.

How to implement transpose matrix in java

The number of rows and columns in a matrix expressed as row columns. The matrix below comprises 2 rows and 3 columns, for a total of 23 dimensions. “Two by three,” is read aloud. The number of columns in the first matrix must equal the number of rows in the second matrix for matrix multiplication to be defined. We use the dot product of a row in A and a column in B to find A B AB AB. Simply write the components of a row as columns and the elements of a column as rows to calculate the transpose of a matrix.

Difference between 2* 2 matrix and 3* 3 matrix

The 2×2 Matrix is a decision-making technique in which possibilities are plotted on a two-by-two matrix. A four-blocker is also known as a magic quadrant. A simple square divided into four equal quadrants forms the matrix diagram. Each axis indicates a criterion for making a decision, such as a price or effort.

Determinants are special numbers computed from the square matrix in matrices. For a matrix with three rows and three columns, the determinant of a 3 x 3 matrix is determined. The determinant is represented by vertical lines on either side of the sign, such as | |.

Write a java program to delete or erase the element in the array in a exact location

Write a java program to delete or erase the element in the array in an exact location. using this program we can delete the array element in java. We begin iterating from the position where the element is to be removed. The reason for this is that all elements after the deleted element will be shifted to the left by one position.

import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int i,n,pos;
System.out.println("Enter no of elements in the array") ;
n = sc.nextInt();
int[] a = new int[n];
System.out.println("Enter the elements") ;
for(i=0;i<n;i++)
{
a[i] = sc.nextInt();
}
System.out.println("Enter the element location of an array to delete the number");
pos = sc.nextInt();
for(i=pos;i<n-1;i++)
{
a[i]=a[i+1];
}
n=n-1;
System.out.println("After deleting the element\n");
for(i=0;i<n;i++)
{
System.out.println("a["+i+"] = "+a[i]);
}
}
}

Output:

Enter no of elements in the array
5
Enter the elements
12
45
67
89
56
Enter the element location of an array to delete the number
2
Nothing is selected to erase is

a[0] = 12
a[1] = 45
a[2] = 89
a[3] = 56

What is Array in delete program

A data structure that contains a group of elements is known as an array. These elements are typically all of the same data type, such as an integer or a string. In computer programs, arrays are commonly used to organize data so that a related set of values can be easily sorted or searched.

How to initilize array in java program for delete program

In Java, we declare an array by giving it a type and a name, just like we do other variables: myArray;  We can use the following shorthand syntax to initialise or instantiate an array as we declare it, meaning we assign values as we create the array: int[] myArray = {13, 14, 15};

Steps to delete the element in java

Get the index and the array.
With the array elements, create an ArrayList.
The remove() method is used to remove the specified index element.
Using the mapToInt() and toArray() methods, create a new ArrayList array.
Return the array that has been formed

For loop uses in array programs

To visit each element of an array, we can use iteration with a for a loop. The process is known as traversing the array. Simply begin at 0 and loop until the index is less than the array’s length. The for loop or for Each loop can be used to traverse an array. Instead of printing each element one by one, you can use the for loop to iterate the index from 0 to the length of the array (ArrayName. length) and access elements at each index.

Write a single dimension array in a java program to modify the element located in the leftwards direction.

Write a single dimension array in a java program to modify the element located in the leftwards direction. A one-dimensional array in the form of a linear array. To access its items, a single subscript is utilized, which can represent a row or column index. The first element in the temp variable is stored in the last position, a[n-1], and the following elements are shifted one position to the left by saving the element in the current position in the previous position.

import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int i,n,temp;
System.out.println("Enter the no of elements") ;
n = sc.nextInt();
int[] a = new int[n];
System.out.println("Enter the elements") ;
for(i=0;i<n;i++)
{
a[i] = sc.nextInt();
}
System.out.println("Before sorting the elements");
for(i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
temp=a[0];
for(i=0;i<n-1;i++)
{
a[i]=a[i+1];
}
a[n-1]=temp;
System.out.println("\nElements after sorting");
for(i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
}
}

Output:

Enter the no of elements
3
Enter the elements
45
67
89
Before sorting the elements
45 67 89
Elements after sorting
67 89 45

What is array in java?

An array is a data structure that contains a collection of elements. The data types of these items are frequently the samea, such as an integer or a string. Arrays are commonly used in computer programs to organize data so that a related group of numbers can be quickly sorted or searched. Arrays can be classified into three types: indexed arrays, multidimensional arrays, and associative arrays. 

Advantages of array in single dimensional program

Using the index number to access an element in an array is very simple.
The search process is simple to apply to an array.
Matrixes are represented using a 2D array.
If a user needs to store multiple values of the same type for any reason, the Array can be used effectively.

Limitations of array programs in java

The dimension of an array is fixed at the time of its creation and cannot be changed later;
Regardless of the number of elements that are actually of interest, the array takes up a proportional amount of memory to its size.

One dimensional array vs multidimensional array in java

A one-dimensional array is a one-dimensional linear array. To access its items, a single subscript is used, which can indicate a row or column index. Consider the C declaration int anArrayName[10], which specifies a one-dimensional array with ten instances. In this case, the array can hold ten int entries. This array’s indices range from zero to nine. The phrases anArrayName[0] and anArrayName[9] are used to represent the first and last elements, respectively.

Sorting algorithm in java using array

Sorting is the process of arranging data in a data structure in a preferred order. Sorting data makes it easier to search through it quickly and efficiently. The most basic example of sorting is a dictionary. A variety of sorting methods are used in computer science.

Java program to change the element position in right direction using single dimension array

Java program to change the element position in the right direction using a single dimension array. A linear array is a form of a one-dimensional array. A single subscript, which can indicate a row or column index, is used to access its items. The last element is stored in the temp variable and then placed in the starting position, which is a[0], while the other items are shifted from one position to the right by storing the element in the current position to the next position.

import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int i,n,temp;
System.out.println("Enter the number of elements in the array") ;
n = sc.nextInt();
int[] a = new int[n];
System.out.println("Enter the elements");
for(i=0;i<n;i++)
{
a[i] = sc.nextInt();
}
System.out.println("Before sorting");
for(i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
temp=a[n-1];
for(i=n-1;i>0;i--)
{
a[i]=a[i-1];
}
a[0]=temp;
System.out.println("\nElements after repositioned");
for(i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
}
}

Output:

Enter the number of elements in the array
3
Enter the elements
34
56
76
Before sorting
34 56 76
Elements after repositioned
76 34 56

What is Array in java programming language and it uses?

A data structure that contains a group of elements is known as an array. These items are often all of the same data type, such as an integer or a string. In a computer program, arrays are widely used to organize data so that a related group of numbers can be readily sorted or searched. 

Array and its uses

Arrays use a single name to represent numerous data elements of the same type. The elements in arrays can be accessed at random using the index number.For all of its elements, arrays allocate memory in contiguous memory regions. As a result, in the case of arrays, there is no probability of extra RAM being allocated. This prevents memory overflow and shortages in arrays. Other data structures, such as linked lists, stacks, queues, trees, and graphs, can be built using arrays. Matrixes are represented using two-dimensional arrays.

Single dimensional Array vs Multi dimensional Array

A one-dimensional array is a linear array of one dimension. A single subscript, which can indicate a row or column index, is used to access its items. Consider the C declaration int anArrayName[10], which declares a ten-instance one-dimensional array. The array can hold ten int entries in this case. The indices in this array range from zero to nine. The first and last elements, for example, are represented by the phrases anArrayName[0] and anArrayName[9].

What is sorting in java

Sorting is the process of arranging data in a preferred order in a data structure. Sorting data makes it easier to swiftly and simply search through it. A dictionary is the most basic example of sorting. In computer science, a variety of sorting methods are utilised.

Java program to print the element using calling methods in the same class

Java program to print the element using calling methods in the same class. This application explains how a method can be called from within a single class. You must first create a class called ‘Main’ within which you will call the main() method in this application. This main() method also calls the Method1() and Method2() methods (). You may now refer to this as a method definition that makes a call to another set of methods. This program will help you how to call a method in java from the same class. 

public class Main
{
public static void main(String[] args)
{
Method1();
Method2();
}
public static void Method1()
{
System.out.println("Welcome to inlarn");
}
public static void Method2()
{
Method1();
}
}

Output:

Welcome to inlarn

Welcome to inlarn

Program in java to print the pie value(pi)

Program in java to print the pie value(pi). The lowercase Greek letter sometimes spelled pi, is used by mathematicians to denote the ratio of a circle’s circumference to its diameter.

It is derived from the initial letter of the Greek word perimeters, which means circumference. is pronounced “pie” in English.  We can utilize the Math.PI constant defined in the java.lang.Math class to get and use the PI () value in Java. 

The Math.PI variable is a static final double type variable with a double value that is the closest to the ratio of a circle’s circumference to its diameter.

PI = 3.14 is the value of pie in java. Because it is a static variable, we can access it directly using its class name, such as Math.PI.

class Main 
{
public static void main(String[] args)
{
double x = Math.PI;
System.out.println(x);
}
}

Output:

3.14159265358979323846

What is pie value and the shocking facts behind the pi value in java

A mathematical constant is a number. It is defined as the circumference to diameter ratio of a circle, with several similar definitions.

Since the mid-eighteenth century, it has been symbolized by the Greek letter “,” which is spelled out as “pi.”

It’s also known as Archimedes’ constant, and it’s pronounced ‘pie.’ It’s one of the most often used constants in mathematics.

It’s the diameter of a circle divided by its circumference. In some aspects, Pi () is a very simple number to calculate; all you have to do is take any circle and divide its circumference by its diameter to get Pi.

Haruka Iwao established a world record by utilizing Google cloud technology to calculate Pi to 31.4 trillion digits. Here’s the entire mind-boggling figure: There are 31,415,926,535,897 digits in this number.

What is Math.pi in java and how to declare in java program

In the Java.lang. math class, the PI constant is defined. The Calculation. PI is a static final double type variable with a double value that is closest to the ratio of a circle’s circumference to its diameter than any other.

The constant keyword can be used to declare constant variables. Macro can be used to specify constants, such as double pi = 3.14 or constant variables. In Java, there are a lot of predefined constants.

Find out duplicate number between 1 to n numbers in java

Find out duplicate numbers between 1 to n numbers in java. Using this program we can find the duplicate number or repeated number in java. Two loops can be used to find duplicate components.

The outer loop iterates across the array from 0 to the array’s length. The element will be chosen by the outer loop. The selected element will be compared to the rest of the array’s elements using the inner loop.

public class Main
{
public static void main(String[] args)
{
int [] arr = new int [] {10,34,56,67,10,56,3};
System.out.println("Duplicate elements are ");
for(int i = 0; i < arr.length; i++)
{
for(int j = i + 1; j < arr.length; j++)
{
if(arr[i] == arr[j])
System.out.println(arr[j]);
}
}
}
}

Duplicate elements are
10
56

What is hash maps and how it find the duplicate element

The HashSet data structure is the most common approach to discover duplicate elements in an array. Set abstract data type does not allow duplicates, as you may recall. This attribute can be used to filter out duplicate elements.

We utilize HashMap to locate duplicates in an array in Java in this method. The components of the input array are stored as keys in the HashMap, and their occurrences are stored as values in the HashMap. If a key’s value is greater than one (>1), that key is a duplicate element.

What is array and how it is useful for daily life to humans

A data structure that contains a group of elements is known as an array. These items are often all of the same data type, such as an integer or a string.

In computer programs, arrays are widely used to organize data so that a related group of numbers can be readily sorted or searched.

Real-life examples of arrays include post office boxes, book pages, egg cartons, and chess pieces.

How to calculate array length in java program

The array length in Java refers to the maximum number of elements that an array can hold. The length of an array cannot be determined using any predefined method.

The array attribute length in Java can be used to determine the array length. This attribute is used in conjunction with the array name.

Write a program to calculate electricity bill in java

Write a program to calculate electricity bill in java. Multiply the wattage of the gadget by the number of hours it is used per day. Multiply by 1000. Subtract your kWh rate from the total.

class Main
{
public static void main(String args[])
{
int unit=500;
double bill=0;
if(unit<100)
{
bill=unit*1.20;
}
else if(unit<300)
{
bill=100*1.20+(unit-100)*2;
}
else if(unit>300)
{
bill=100*1.20+200*2+(unit-300)*3;
}
System.out.println("Electric bill calculator" + bill);
}
}

Electric bill calculator1120.0

Write a array program to calculate average and sum in java

Write a array program to calculate average and sum in java. Calculate the sum and average of an array in Java. Enter the array’s size, followed by all of the array’s elements. Now, using the for loop, we calculate the sum of the array’s elements and divide it by the number of items in the array to get the average. the Java source code for calculating the sum and average of an array

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, sum = 0;
float average;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements you want in array");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter all the elements");
for(int i = 0; i < n ; i++)
{
a[i] = s.nextInt();
sum = sum + a[i];
}
System.out.println("Sum"+sum);
average = (int)sum / n;
System.out.println("Average"+average);
}
}

Enter number of elements you want in array 5
Enter all the elements
34
56
78
23
45
Sum236
Average47.0

Write a java program to split an array in a specific position

Write a java program to split an array in a specific position. Splitting an array from a specific location with a Java program. Enter the array’s size, followed by all of the array’s elements. Now type in the location where you want to divide from. The elements from the first position are copied to the second array, and the remaining elements are copied to the third array. the Java source code for Splitting an Array from a Specific Position

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, x, flag = 1, local = 0, k = 0,j = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number of elements you want in array");
n = s.nextInt();
int a[] = new int[n];
int b[] = new int[n];
int c[] = new int[n];
System.out.println("Enter all the elements");
for (int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
System.out.print("Enter the position from where you want to split");
local = s.nextInt();
for(int i = 0; i < local; i++)
{
b[k] = a[i];
k++;
}
for(int i = local; i < n; i++)
{
c[j] = a[i];
j++;
}
System.out.print("First array");
for(int i = 0;i < k; i++)
{
System.out.print(b[i]+" ");
}
System.out.println("");
System.out.print("Second array");
for(int i = 0; i < j; i++)
{
System.out.print(c[i]+" ");
}
}
}

Enter the number of elements you want in array 5
Enter all the elements
34
56
678
23
12
Enter the position from where you want to split 678

First array 34 56

Second array 23 12

Write a java program to arrange strings in alphabetical order

Write a java program to arrange strings in alphabetical order. Sorting names in alphabetical order with a Java program. Enter the array’s size, then all of the names in the array. We can now quickly arrange names in alphabetical order using the compareTo operator.The Java Program to Sort Names in Alphabetical Order source code is available here.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of name you want to enter");
n = s.nextInt();
String names[] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println("Enter all the name");
for(int i = 0; i < n; i++)
{
names[i] = s1.nextLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.print("Names in sorted Order");
for (int i = 0; i < n - 1; i++)
{
System.out.print(names[i] + ",");
}
System.out.print(names[n - 1]);
}
}

Enter number of name you want to enter 3
Enter all the name
apple
microsoft
inlarn
Names in sorted Orderapple,inlarn,microsoft

Write a java program to delete an element from an array list at the specified index

Write a java program to delete an element from an array list at the specified index. Delete the specified integer from an array with a Java program.Enter the array’s size, followed by all of the array’s elements. Now type in the element you wish to get rid of. We locate the element’s location first, then shift the positions of all the elements after the element to be deleted is removed one by one. the Java source code for the Delete the Specified Integer from an Array program.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, x, flag = 1, loc = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the numbers that you want in array");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter all the elements");
for (int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
System.out.print("Enter the element you want to delete");
x = s.nextInt();
for (int i = 0; i < n; i++)
{
if(a[i] == x)
{
flag =1;
loc = i;
break;
}
else
{
flag = 0;
}
}
if(flag == 1)
{
for(int i = loc+1; i < n; i++)
{
a[i-1] = a[i];
}
System.out.print("After deleting the numbers");
for (int i = 0; i < n-2; i++)
{
System.out.print(a[i]+",");
}
System.out.print(a[n-2]);
}
else
{
System.out.println("Element not found");
}
}
}

Enter the numbers that you want in array 5
Enter all the elements
34
56
78
89
12
Enter the element you want to delete56
After deleting the numbers34,78,89,12

Write a java program to add element in user-specified position using array

Write a java program to add element in user-specified position using array. In a given Array, a Java program to add an element in a specific position. Enter the array’s size, followed by all of the array’s elements. Now type in the element you want to insert and the location where you want it to go. We shift all the elements in the array by one to make it easier to insert the element.

 import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, pos, x;
Scanner s = new Scanner(System.in);
System.out.print("Enter no. of elements you want in array");
n = s.nextInt();
int a[] = new int[n+1];
System.out.println("Enter all the elements");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
System.out.print("Enter the position where you want to add the element");
pos = s.nextInt();
System.out.print("Enter the element you want to add");
x = s.nextInt();
for(int i = (n-1); i >= (pos-1); i--)
{
a[i+1] = a[i];
}
a[pos-1] = x;
System.out.print("After adding the element");
for(int i = 0; i < n; i++)
{
System.out.print(a[i]+",");
}
System.out.print(a[n]);
}
}

Enter no. of elements you want in array5
Enter all the elements
23
45
67
78
55
Enter the position where you want to add the element3
Enter the element you want to add100
After adding the element23,45,100,67,78,55

Write a java program to find the odd or even number in the array

Write a java program to find the odd or even number in the array. Even and Odd Elements of an Array are Separated in Two Arrays by a Java Program.  Enter the array’s size, followed by all of the array’s elements. Now, using the for loop and the if condition, we can determine whether the value is odd or not, and print it accordingly. the source code for a Java program that divides an array’s even and odd elements into two separate arrays.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, j = 0, k = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter no of elements you want in array");
n = s.nextInt();
int a[] = new int[n];
int odd[] = new int[n];
int even[] = new int[n];
System.out.println("Enter all the elements");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
for(int i = 0; i < n; i++)
{
if(a[i] % 2 != 0)
{
odd[j] = a[i];
j++;
}
else
{
even[k] = a[i];
k++;
}
}
System.out.print("Odd");
if(j > 1)
{
for(int i = 0;i < (j-1); i++)
{
System.out.print(odd[i]+",");
}
System.out.print(odd[j-1]);
}
else
{
System.out.println("No number");
}
System.out.println("");
System.out.print("Even");
if(k > 1)
{
for(int i = 0; i < (k-1); i++)
{
System.out.print(even[i]+",");
}
System.out.print(even[k-1]);
}
else
{
System.out.println("No number");
}
}
}

Enter no. of elements you want in array 2
Enter all the elements
34
56
Odd No number

Even 34,56

Write a program to find second largest number in an array in java

Write a program to find second largest number in an array in java. Finding the Second Largest and Smallest Elements in an Array with Enter the array’s size, followed by all of the array’s elements. We now sort the array in ascending order using the for loop and temp variable. As a result, the first and second last elements are returned as output. The Java Program to Find the Second Largest and Smallest Elements in an Array source code

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter no of elements you want in array");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter all the elements");
for (int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.println("Second Largest"+a[n-2]);
System.out.println("Smallest"+a[0]);
}
}

Enter no of elements you want in array 2
Enter all the elements
34
56
Second Largest34
Smallest34

Write a java program to find the largest number in an array

Write a java program to find the largest number in an array. Find the largest two numbers in an array with a Java program.Enter the array’s size, followed by all of the array’s elements. Using double for loops, we first sort the array in decreasing order, yielding the first two elements as output. The Java Program to Find the Largest Two Numbers in an Array source code is available here.

import java.util.Scanner;
public class Main
{
public static void main (String[] args)
{
Scanner scn = new Scanner (System.in);
System.out.print("Enter no f elements you want in array");
int n = scn.nextInt();

int array[] = new int[n];
System.out.println("Enter all the elements");
for (int i = 0; i < array.length; i++)
{
array[i] = scn.nextInt();
}

int high1, high2, temp;

high1 = array[0];
high2 = array[1];

if (high1 < high2)
{
temp = high1;
high1 = high2;
high2 = temp;
}

for (int i = 2; i < array.length; i++)
{
if (array[i] > high1)
{
high2 = high1;
high1 = array[i];
}
else if (array[i] > high2 && array[i] != high1)
{
high2 = array[i];
}
}

System.out.println ("The highest number"+high1);
System.out.println ("The lowest number"+ high2);

}
}

Enter no f elements you want in array2
Enter all the elements
45
565
The highest number565
The lowest number45

How to print semicolon in java program without using it

How to print semicolon in java program without using it. Without using a semicolon anywhere in the code, a Java program will print a semicolon. We assign the value of fifty nine to an integer variable. Now, using Implicit Casting, we convert this integer value to char, and because the ASCII value of a semicolon is fifty-nine, the result is a semicolon.Without using a semicolon anywhere in the code, a Java program will print a semicolon.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n;
char a;
n = 59;
a = (char) n;
System.out.println(a);
}
}

;

Write a program to concatenate two string in java

Write a program to concatenate two string in java. Concatenation of strings with a Java program. As input, choose any two strings. We’ve created a function to which we input the two specified strings, and this function concatenates the strings using the concatenation operator, returning the desired result to the main function.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
String a, b, c;
Scanner s = new Scanner(System.in);
System.out.print("Enter first string");
a = s.nextLine();
System.out.print("Enter second string");
b = s.nextLine();
Main obj = new Main();
c = obj.concat(a, b);
System.out.println("New String"+c);
}
String concat(String x, String y)
{
String z;
z = x + " " + y;
return z;
}
}

Enter first string inlarn
Enter second string.com
New String inlarn .com

Write a java program to print the nested methods to perform mathematical operations

Write a java program to print the nested methods to perform mathematical operations. This is a Java program that demonstrates method nesting. Nesting of methods occurs when a Java method calls another method in the same class.Fill in the blanks with length, width, and height. After that, we call the volume method for the first time. The area method is derived from the volume technique, while the perimeter technique is derived from the area method. As a result, the perimeter, area, and volume of a cuboid are computed.

import java.util.Scanner;
public class Main
{
int perimeter(int l, int b)
{
int pr = 12 * (l + b);
return pr;
}
int area(int l, int b)
{
int pr = perimeter(l, b);
System.out.println("Perimeter"+pr);
int ar = 6 * l * b;
return ar;
}
int volume(int l, int b, int h)
{
int ar = area(l, b);
System.out.println("Area"+ar);
int vol ;
vol = l * b * h;
return vol;
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.print("Enter length of the cuboid");
int l = s.nextInt();
System.out.print("Enter breadth of the cuboid");
int b = s.nextInt();
System.out.print("Enter height of the cuboid");
int h = s.nextInt();
Main obj = new Main();
int vol = obj.volume(l, b, h);
System.out.println("Volume"+vol);
}
}

Enter length of the cuboid 34
Enter breadth of the cuboid 34
Enter height of the cuboid 34
Perimeter 816
Area 6936
Volume 39304

Method Overloading in Java to Find Arithmetic Sum of 2 or 3 or 4 Variables by Passing Argument

Method Overloading in Java to Find Arithmetic Sum of 2 or 3 or 4 Variables by Passing Argument. This is a Java program that uses method overloading to find the arithmetic sum of two, three, or four variables. Overloaded methods are two or more methods inside the same class that have the same name but distinct argument declarations, and the practise is known as method overloading. We’ve created a class with three methods, each with the same name but a different number of parameters. Now, depending on the amount of parameters supplied, various methods can be called. As a result, we receive three different output values.

public class Main
{
int add(int a, int b)
{
int sum;
sum = a + b;
return sum;
}
int add(int a, int b, int c)
{
int sum;
sum = a + b + c;
return sum;
}
int add(int a, int b, int c, int w)
{
int sum;
sum = a + b + c + w;
return sum;
}
public static void main(String[] args)
{
Main obj = new Main();
int a = obj.add(100, 150);
System.out.println("Sum with two arguments"+a);
int b = obj.add(50, 100, 150);
System.out.println("Sum with three arguments"+b);
int c = obj.add(100, 150, 200, 250);
System.out.println("Sum with four arguments"+c);
}
}

Sum with two arguments 250
Sum with three arguments 300
Sum with four arguments 700

Java program calculation to fill the bucket with the water mug

Java program calculation to fill the bucket with the water mug. A bucket with a capacity of x litres is expected to be filled with a cup with a capacity of y millilitres. If x=50 and y=5, the bucket will be filled with a minimum of 6 mugs.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the values");
int bucketCap = sc.nextInt();
if(bucketCap>0) {
int mugCap = sc.nextInt();
if(mugCap>0){
double fullbucket = bucketCap*0.8;
int fill=0;
System.out.println("Enter big numbers");
while (fill<fullbucket){
int a = sc.nextInt();
if(a<=mugCap){
fill +=a;
}
else {
System.out.println("Invalid");
}
}

}
else {
System.out.println("Invalid");
}
}
else {
System.out.println("Invalid");
}
}
}

Enter the values
2
2
Enter big numbers
45
Invalid

Java program to solve quadratic equation using if-else

Java program to solve quadratic equation using if-else. A quadratic equation is a second-degree equation, meaning it contains at least one squared element. ax2 + bx + c = 0 is the conventional form, with a, b, and c being numerical coefficients and x being an unknown variable.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
double root1, root2;
double determinant = b * b - 4 * a * c;
if(determinant > 0) {
root1 = (-b + Math.sqrt(determinant)) / (2 * a);
root2 = (-b - Math.sqrt(determinant)) / (2 * a);
System.out.format("root1 = %.2f and root2 = %.2f", root1 , root2);
}
else if(determinant == 0) {
root1 = root2 = -b / (2 * a);
System.out.format("root1 = root2 = %.2f;", root1);
}
else {
double real = -b / (2 *a);
double img = Math.sqrt(-determinant) / (2 * a);
System.out.format("root1 = %.2f+%.2fi and root2 = %.2f-%.2fi", real, img, real, img);
}
}
}

45
34
56
root1 = -0.38+1.05i and root2 = -0.38-1.05i

Java program to print weekdays using a switch statement

Java program to print weekdays using a switch statement. This Java software can assist you in determining the weekdays order. The user is prompted to input a valid week number in the program below. Check the week number using the switch case after collecting the value from the user program and display the relevant day. I assumed, like the previous program, that Monday is the beginning day of the week.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the week days");
int weekday = scanner.nextInt();
if(weekday == 1)
{
System.out.println("Monday");
} else if(weekday == 2)
{
System.out.println("Tuesday");
} else if(weekday == 3) {
System.out.println("Wednesday");
} else if(weekday == 4) {
System.out.println("Thursday");
} else if(weekday == 5) {
System.out.println("Friday");
} else if(weekday == 6) {
System.out.println("Saturday");
} else if(weekday == 7) {
System.out.println("Sunday");
} else {
System.out.println("Enter the numbers between 1 to 7");
}
}
}

Enter the week days
4
Thursday

Java program to find the cubes of an n natural numbers

Java program to find the cubes of an n natural numbers. In this tutorial, we’ll construct two Java programs that use the For Loop and While Loop to find the cube of numbers up to a certain integer. Using the for and while loops, the program will find the cude of the first N numbers.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number ");
int num = sc.nextInt();
for (int i=1;i<=num;i++)
{
System.out.println("Number is "+i+" and cube of "+i+" is "+(i*i*i));
}
}
}

Enter the number 5
Number is 1 and cube of 1 is 1
Number is 2 and cube of 2 is 8
Number is 3 and cube of 3 is 27
Number is 4 and cube of 4 is 64
Number is 5 and cube of 5 is 125

Java program to find middle element of string

Java program to find the middle element of the string. This program will print the center element in this input. Write a Java program that reads a string from the user and retrieves the middle characters in the string’s center from the input string and returns it as a string output.

import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the string");
String str = sc.nextLine();
char ch[] = str.toLowerCase().toCharArray();
int c=0;
int v=0;
String sp="";
if(str.length()<3)
{
System.out.println("The string should not have "+str+" is too short");
}
else{

for (int i=0;i<ch.length;i++) {

if (ch[i] >= 'a' && ch[i] <= 'z') {
c++;
} else {
sp += ch[i];
v++;
}

}
if(ch.length!=c)
{
System.out.println("this string shouldnt have");
System.out.println(sp);
}
else if(ch.length==c){
System.out.println("middle charecters");
if(ch.length%2==0){
String out = ""+ch[(ch.length/2)-1]+ch[(ch.length/2)];
System.out.println(out);
}
else{
String out = ""+ch[ch.length/2];
System.out.println(out);
}
}

}
}
}

Output:

Enter the string
thilagar
middle charecters
la

Java code for car parking management system

Java code for car parking management system. This program will help you to find the free parking space for cars. By using this program we easily find out which is free space in parking lot.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
if(num>=1 && num<=50){
System.out.println("a1");
}
else if(num>=51 && num<=100){
System.out.println("a2");
}
else if(num>=101 && num<=120){
System.out.println("a3");
}
else if(num>=121 && num<=180){
System.out.println("a4");
}
else{
System.out.println("Invalid Input");
}

}
}

60

a3

Java program to create a login page with username and password

Java program to create a login page with username and password. Make preparations to develop an application. Make the decision to create a login page. Before utilising the program, users must first register and login. They must establish a login page that is only accessible to registered users. Create a Java programme to assist them in building a rudimentary model for their app by collecting registration information, storing it, and confirming the login procedure.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sp=" ";
System.out.println("Enter the username");
String name = sc.nextLine();
if((name.contains(sp)) || name.length()<4){
System.out.println("Invalid username");
return;
}
System.out.println("Enter the password");
String pass = sc.nextLine();
if((pass.contains(sp)) || pass.length()<8)
{
System.out.println("Invalid password");
return;
}
System.out.println(name+" you are registered successfully");
System.out.println("Enter the username");
String lname = sc.nextLine();
System.out.println("Enter the password");
String lpass = sc.nextLine();
if(name.equals(lname) && pass.equals(lpass)){
System.out.println("Welcome "+lname+" you have logged-in successfully");
}
else{
System.out.println("Username or password mismatch");
}
}
}

Output:

Enter the username
raghu
Enter the password
456
Invalid password

Java program to find the odd or even in the box challenge

Java program to find the odd or even in the box challenge. The numbers in the input must be bigger than zero. Otherwise, print “is not a valid input” and exit. Print “is even it’s a valid box” if the sum is even.If the sum is odd, print “is odd, this box is invalid.” If the box contains balls that are less than zero, print “is not a valid input.” Please do not terminate the programme with System.exit.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("The box contains");
int num = sc.nextInt();
if(num<0)
{
System.out.println(num+" is not a valid input");
return;
}
else{
System.out.println("Enter the number");
int arr[] = new int[num];
int sum =0;
for (int i=0;i<num;i++)
{
int a = sc.nextInt();
if(a>0){
arr[i] = a;
sum += (arr[i]%10);
}
else{
System.out.println(a+" is not a valid input");
}
}

if(sum%2==0){
System.out.println(sum+" is even its valid box");
}
else {
System.out.println(sum+" is odd its invalid box");
}

}
}
}

Output:

The box contains
2
Enter the number
45
56
11 is odd its invalid box

Java program to calculate cubic capacity cc in bikes

Java program to calculate cubic capacity cc in bikes. The cubic capacity of a motorcycle’s engine is the unit of measurement. Vehicle cubic capacity, generally known as “cc,” typically ranges from 50cc to 1500cc. The larger the chamber of a two-wheeler, the more powerful it is thought to be. The capacity of a bike is calculated in the same manner as the engine capacity of a four-wheeler vehicle is measured in litres.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int cc = sc.nextInt();

if(100>cc){
System.out.println("Enter the large number");
}
if(100<=cc && 125>=cc){
System.out.println(75);
}
if(126<=cc && 135>=cc){
System.out.println(70);
}
if(136<=cc && 150>=cc){
System.out.println(60);
}
if(151<=cc && 200>=cc){
System.out.println(50);
}
if(201<=cc && 220>=cc){
System.out.println(35);
}
if(cc>220){
System.out.println("The number is very large");
}
}
}

Output

220
35

Java program to kindergarten school kids

Java program to kindergarten school kids. A word is expected to be repeated five times by Kindergarten students. For instance, if the word is “running,” they must say “running.” Write a software that accepts the user’s string (word) as input and also gets the X and Y position of the character as input. If the characters in the Xth and Yth positions are the same, print “Same,” otherwise “Not Same.”

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String str = sc.next();
int pos1 = sc.nextInt();
int pos2 = sc.nextInt();
String a="";
for (int i=1;i<=5;i++)
{
a+=str;
}
System.out.println(a);
if(a.charAt(pos1)==a.charAt(pos2)){
System.out.println("Same");
}
else{
System.out.println("Not Same");
}

}
}

run
34
45
runrunrunrunrun

Java program to calculation the air conditioner capacity for invertor and non invertor

Java program to calculation the air conditioner capacity for invertor and non invertor. In order to place bulk orders, the Manager of Vasanth & Co showroom wants to know the stock of inverter and non-inverter air conditioners. As a result, the warehouse crew counts the inverter and non-inverter air conditioners individually, which are stored on racks. Using your Java abilities, assist them with counting.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n;
System.out.println("Total count of Air Conditioner");
n = sc.nextInt();
sc.nextInt();
int count=0;
int count1=0;
String ac[] = new String[n];
System.out.println("List of Air Conditioners");
for (int i=0;i<n;i++){
ac[i] = sc.nextLine();
if(ac[i].equalsIgnoreCase("Inverter"))
{
count++;
}
else if(ac[i].equalsIgnoreCase("Non-Inverter"))
{
count1++;
}
else {
System.out.println(ac[i]+" Air Conditioner is not avaiable");
System.exit(0);
}
}
System.out.println("Inverter AC is of count "+count);
System.out.println("Non-Inverter AC is of count "+count1);
}
}

Output:

Total count of Air Conditioner
2
1
List of Air Conditioners
Air Conditioner is not avaiable

Java program to calculate land price with land area

Java program to calculate land price with land area. They offer cheap independent home layouts, apartments, and private villas. The management of Thilagar Real Estate intends to offer a significant discount to its customers.

The discount is calculated based on the amount of land that has been reserved or purchased. Write a Java program to determine the total price the buyer must pay, taking into account any discounts that may be available.

import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
double total =0;
System.out.println("Enter the land buyer name");
String name =sc.nextLine();
System.out.println("Enter the lands size in acres");
int area = sc.nextInt();
sc.nextLine();
if(area>=400 && area<=599){
total = area*1700;
total = total * 0.95;
}
else if(area>=600 && area<=999){
total = area*1900;
total = total * 0.95;
}
else if(area>=1000 && area<=2600){
total = area*2600;
total = total * 0.96;
}
else if(area>=2500 && area<=3000){
total = area*2800;
total = total * 0.97;
}
else{
System.out.println(area+" is out of range");
return;
}
System.out.println("Total amount after discount is \n"+total);
}
}

 

Output:

Enter the land buyer name
Raghu
Enter the lands size in acres
500
Total amount after discount is
807500.0

What is if else statement in java and how to implement if else condition

The conditional statements in Java are as follows: If a particular condition is true, use if to specify a block of code to be run. If the same condition is false, use otherwise to specify a block of code to run. If the initial condition is false, use else if to define a new condition to test.

What is AND operator in java program

If both operands are true, the logical AND operator (&&) returns true; otherwise, it returns false. The logical AND operator’s operands do not have to be of the same type, but they must be of the boolean, integral, or pointer type. Relational or equality expressions are frequently used as operands.

What is acres and how to calculate in java program

Multiply your length and width to get square feet to calculate acres by hand. If you need to convert lengths, use our length conversion tools. Then divide the result by 43,560 to get the land area in acres. Using our square feet area calculator, you can rapidly calculate the square footage of a given space.

What is hectare and how to calculate in java program

In the metric system, a hectare is equal to 100 acres, or 10,000 square meters, and in the British Imperial System and the United States Customary measure, a hectare is equal to 2.471 acres. The name comes from the Latin word area and the Greek word hecter, which is an irregular abbreviation of the word hundred.

Java program to calculate uber cost and discount rate

Java program to calculate uber cost and discount rate. Uber is one of the most popular taxi services in town. Uber’s owner intends to offer a significant discount to its clients. The discount is calculated according to the distance travelled. Create a Java software to determine the total fare for the consumer, taking into account any applicable discounts.

import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
double money =0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the name");
String name = sc.nextLine();
System.out.println("Enter distance travelled by the customer");
int dist = sc.nextInt();

if(dist<200 || dist>5000){
System.out.println(dist+" is out of range");
return;
}
else if(dist>= 200 && dist<=500){
money = dist*12;
money = money * 0.97;
}
else if(dist>= 501 && dist <=1000){
money = dist*10;
money = money * 0.95;
}
else if(dist>= 1001 && dist <= 2999){
money = dist*10;
money = money * 0.90;
}
else if(dist>= 3000 && dist <=5000){
money = dist*8;
money = money * 0.85;
}
System.out.println("Total money after discount is "+money);

}
}

Enter the name
raghu
Enter distance travelled by the customer
350
Total money after discount is 4074.0

Java program to find numerology number

Java program to find numerology number. Ram has found a new interest in numerology and has begun to pay attention to the numbers that appear in his daily routines. Make a program to assist him. The application should take the user’s input and show the digits one at a time, separated by a single space. Assume the value of the input is less than 500000. Display the sum of the digits, the numerology number, as well as the total amount of odd and even numbers.

import java.util.Scanner;
public class Main
{
public static void main (String[] args)
{
String str_num="";
int sum=0, even=0, odd=0, numerology=0, r=0;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number");
int num=sc.nextInt();
int temp=num;

while(temp>0)
{
r=temp%10;
str_num=(char)(r+'0')+" "+str_num;
sum+=r;
if(r%2==0)
{
even++;
}
else
{
odd++;
}
temp/=10;
}
numerology=sum;
Main obj=new Main();
while(numerology>9)
{
numerology=obj.numer(numerology);
}System.out.println("The Number is"+str_num);
System.out.println("Sum of digits"+sum);
System.out.println("Numerology number"+numerology);
System.out.println("Number of odd numbers"+odd);
System.out.println("Number of even numbers"+even);

}int numer(int a)
{
int ans=0, temp=a, r=0;
while(temp>0)
{
r=temp%10;
ans+=r;
temp/=10;
}
return ans;
}
}

Enter the number
4
The Number is4
Sum of digits4
Numerology number4
Number of odd numbers0
Number of even numbers1

Java program to count the number of pencils for student

Java program to count the number of pencils for student. Thliagar writes with pencils at school and at home. His parents purchased her one pencil while he was in first grade. He required 5 pencils in her second grade, 14 pencils in his third grade, and so on. From the provided standard, how many pencils does he get?

import java.util.Scanner;
public class Main
{
public static void main (String[] args) {
int penc=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the student's Standard");
int stan=sc.nextInt();
if(stan<1||stan>12)
{
System.out.println("invalid standard or above 1 and below 12");
}
else
{
for(int i=1;i<=stan;i++)
{
penc+=i*i;
}
System.out.println("Thilagar gets "+penc+" pencils");
}
}
}

Output:

Enter the student’s Standard
33
invalid standard or above 1 and below 12

What is logical OR in java program and how to implement

|| is a logical operator that can be read as “OR OR” or “Logical OR.” This operator is used to conduct a “logical OR” operation, which is comparable to the OR gate function in digital electronics.

If the first condition is true, the logical || operator does not examine the second condition. It only tests the second condition if the first is false. Whether the first condition is true or false, the bitwise | operator always verifies both criteria.

What is for loop and how to execute in java

Initialization happens first and only once in a for loop, which means that the initialization component of the for loop only runs once. Second step: Each iteration of the for loop evaluates the condition; if the condition is true, the statements within the for loop body are performed.

What is if else statement in java

The conditional statements in Java are as follows: If a particular condition is true, use if to specify a block of code to be run. If the same condition is false, use otherwise to specify a block of code to run. If the initial condition is false, use else if to define a new condition to test.

Credit score program in java for shop

Credit score program in java for shop. Amazon is an online shopping site that gives out gift cards to its loyal customers. A fixed amount of shopping credit points can be used to redeem the voucher. A user sends each credit point one by one. Because there is such a large crowd, you must handle the users on a first-come, first-served basis.You’re given an array in which you can store each user’s credit points in a first-come, first-served basis. At any given time, you can serve K people. Finally, you must show the credit information for those who have not yet been served. Print “0 users to serve” if all users are served at the same time.

import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of users\n");
int n=sc.nextInt();
System.out.println();
if(n>=1 && n<=1000)
{
int[] a=new int[n];
int temp=0;
while(temp<n)
{
System.out.print("Enter the credit points for user\n "+(temp+1));
a[temp]=sc.nextInt();
if(a[temp]>=1 && a[temp]<=100)
{
temp++;
System.out.println();
}
else
{
break;
}
}

System.out.print("Enter the no. of users to distribute\n");
int k=sc.nextInt();

if(k>=1 && k<n)
{
System.out.print("The undistributed users credit points are\n");
for(int i=(k);i<n;i++)
{
System.out.print(a[i]+" ");
}
}
else if(k==n)
{
System.out.println("There is no users to distribute\n");
}
else
{
System.out.println("Invalid number of users\n");
}

}
else{
System.out.println("Invalid number of users\n");
}
}
}

Enter the number of users
1

Enter the credit points for user
145

Enter the no. of users to distribute
1
There is no users to distribute

write a java program to find my lucky number or not

Write a java program to find my lucky number or not. Thilagar intended to give his car a four-digit fortunate number. The numbers 3,5 and 7 are auspicious for him. Assist him in locating the number whose sum is divisible by three, five, or seven. Please provide a valid vehicle identification number. If a valid input is not provided, the message “This number is not a valid vehicle number” is displayed.

import java.util.Scanner;
public class Main
{
public static void main (String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the vehicle number");
int num=sc.nextInt();
if(num<1000 || num>9999)
{
System.out.println(num+" is not a valid vehicle number");
}
else
{int sum=0;
while(num>0)
{
sum+=num%10;
num/=10;
}
if(sum%3==0 || sum%5==0 || sum%7==0)
{
System.out.println("Lucky number");
}
else
{
System.out.println("Sorry its not my lucky number");
}
}
}
}

Enter the vehicle number
9897
Lucky number

Java program to find which department has highest placement program

Java program to find which department has highest placement program. VSB College wishes to honour the department that has received the most number of placements for the current academic year. The departments that took part in the recruitment campaign were three in all. Assist the college in locating the department with the most placements.

import java.util.Scanner;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter no of students placed in Computer science");
int Computerscience= sc.nextInt();
System.out.println("Enter no of students placed in Electronics");
int Electronics=sc.nextInt();
System.out.println("Enter no of students placed in Mechanical");
int Mechanical=sc.nextInt();

if(Computerscience<0||Electronics<0||Mechanical<0)
{
System.out.println("Enter the number properly");
}
else if(Computerscience==Electronics && Electronics==Mechanical)
{
System.out.println("None of the department has got the highest placement");
}

else if(Computerscience==Electronics && Mechanical<Computerscience)
{
System.out.println("Highest placement");
System.out.println("Computer science");
System.out.println("Electronics");
}

else if(Computerscience==Mechanical && Electronics<Mechanical)
{
System.out.println("Highest placement");
System.out.println("Computer science");
System.out.println("Mechanical");
}

else if(Electronics==Mechanical && Computerscience<Mechanical)
{
System.out.println("Highest placement");
System.out.println("Electronics");
System.out.println("Mechanical");
}

else if(Computerscience>Electronics&&Computerscience>Mechanical)
{
System.out.println("Highest placement");
System.out.println("Computer science");
}

else if(Electronics>Computerscience && Electronics>Mechanical)
{
System.out.println("Highest placement");
System.out.println("Electronics");
}

else if(Mechanical>Computerscience && Mechanical>Electronics)
{
System.out.println("Highest placement");
System.out.println("Mechanical");
}
}
}

Output:

Enter no of students placed in Computer science
400
Enter no of students placed in Electronics
200
Enter no of students placed in Mechanical
100
Highest placement
Computer science

Difference between if else and if else ladder in java

When the if the condition is false, it instructs the code what to do. The if-else-if ladder statement combines numerous statements into one condition. If the statement in the if block evaluates to true, it will be executed. The last else block is assessed if none of the if conditions evaluate to true.

Disadvantages of nested if else program in java

The nested ifs are difficult to comprehend and change. The readability of the program reduces as the depth of nesting grows. When a sequence of decisions must be made one after the other, each decision or condition may include expressions that result in an integer number.

What is if else ladder program in java and how to implement in program

The if-else-if ladder is a typical programming construct that is built on nested ifs. This is how it seems. From the top-down, conditional expressions are evaluated. The statement associated with a true condition is executed as soon as it is found, and the rest of the ladder is skipped.

What is campus placement program in college

Campus placement, often known as campus recruiting, is a program that provides jobs to students nearing the end of their studies at universities or other educational institutions. Companies who want to recruit from the student population cooperate with educational institutions in this type of initiative.

Java program for banking ticket system using if-else statement

Java program for banking ticket system using if-else statement. Each customer receives a ticket and is served when their number is called in a bank’s ticketing system. Consider the following scenario: five consumers each take a ticket from our ticketing system. The first customer has a ticket with the number 3 on it, while the fifth has a ticket with the number 10.Customers who purchase tickets should form a line, with the customer with the first ticket being served first. When the first customer has been served, the ticket in question is withdrawn from the line.

import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter the number of the customer");
int n=sc.nextInt();
if(n>0)
{
int[] Main=new int[n];

System.out.println("The ticket in the system is");
for(int i=0;i<n;i++)
{
Main[i]=i+1;
System.out.print(Main[i]+" ");
}
System.out.println();
System.out.println("Enter the number of ticket distributed ");
int served=sc.nextInt();

if(served>0 && served<=n)
{
System.out.println("The distributed tickets are");
for(int i=0;i<served;i++)
{
System.out.print(Main[i]+" ");
}
System.out.println();

if(served!=n)
{
System.out.println("The undistributed tickets are:");
for(int i=served;i<n;i++)
{
System.out.print(Main[i]+" ");
}
}
else
{
System.out.println("No more mains to be served");
}
}

}
else
{
System.out.println("Invalid Number");
}

}
}

Enter the number of the customer
4
The ticket in the system is
1 2 3 4
Enter the number of ticket distributed
3
The distributed tickets are
1 2 3
The undistributed tickets are:
4

Write a java program to increment every element of the array by one

Write a java program to increment every element of the array by one. This is a Java program that prints the incremented array and increments each element of the array by one. Enter the array’s size, followed by all of the array’s elements.

Using the for loop, we can now increment all of the array’s elements. Here is the Java source code for incrementing every element of an array by one and printing the incremented array.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, i = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter no of elements you want in array");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter all the elements");
for(i = 0; i < n; i++)
{
a[i] = s.nextInt();
a[i]++;
}
System.out.print("Elements of array after increment by 1");
for(i = 0; i < n - 1; i++)
{
System.out.print(a[i]+",");
}
System.out.print(a[n-1]);
}
}

Output:

Enter no of elements you want in array2
Enter all the elements
45
34
Elements of array after increment by 146,35

How to increment the array in java program

To modify the size, build a new array of the appropriate size, copy elements from the old array to the new array, then utilise the new array. Arr can only hold int values in our case. In contrast to ArrayList, which can only carry object values, arrays can hold primitive values.

Write a java program to sort the names in ascending order

Write a java program to sort the names in ascending order. This is a Java program for alphabetically sorting names. Enter the array’s size, then all of the names in the array. 

We can now quickly arrange names in alphabetical order using the compare to operator.The Java program to sort names in Alphabetical Order source code is available here.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of names you want to enter");
n = s.nextInt();
String names[] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println("Enter all the names");
for(int i = 0; i < n; i++)
{
names[i] = s1.nextLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.print("names in sorted order");
for (int i = 0; i < n - 1; i++)
{
System.out.print(names[i] + ",");
}
System.out.print(names[n - 1]);
}
}

Output:

number of names you want to enter 4
Enter all the names
34
45
56
54
names in sorted order34,45,54,56

What is for loop and how does it works in java

A for loop is a repetition control structure that allows you to design a loop that must be repeated a certain number of times quickly. When you know how many times a task will be repeated, a for loop comes in handy.

A loop is used to repeatedly execute a set of statements until a certain condition is met. When showing numbers from 1 to 100, for example, you might wish to set the value of a variable to 1 and display it 100 times, raising its value by 1 with each loop iteration.

What is nextline() in java programming

nextLine() The java. util. nextLine() function is used to get the next line in a string. The Scanner class searches for a line separator delimiter starting at the current location. The String from the current place to the end of the line is returned by this method.

Java program to find the second biggest and smallest number in the array

Java program to find the second biggest and smallest number in the array. Find the Second Largest and Smallest Elements in an Array with this Java Program. Enter the array’s size, followed by all of the array’s elements. We now sort the array in ascending order using the for loop and temp variable.

As a result, the first and second last elements are returned as output. The Java Program to Find the Second Largest and Smallest Elements in an Array source code is available here.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter no of elements you want in array");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter all the elements");
for (int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.println("Second Largest:"+a[n-2]);
System.out.println("Smallest:"+a[0]);
}
}

Output:

Enter no of elements you want in array 2
Enter all the elements
45
67
Second Largest:45
Smallest:45

How to use temp variable in java program

A temporary array persists only for the period of the data step in which it is defined. A temporary array can be used to store constant values used in calculations. There are no comparable variables to identify the array elements in a temporary array.

Write a java program for atm machine

Write a java program for atm machine. This is a Java program that shows how to display an ATM transaction. As input, the user will select one of the offered alternatives. For different procedures such as withdraw, deposit, and check balance, multiple switch cases have been supplied.

import java.util.Scanner;
public class Main
{
public static void main(String args[] )
{
int balance = 1000, withdraw, deposit;
Scanner s = new Scanner(System.in);
while(true)
{
System.out.println("Welcome to State bank of india");
System.out.println("Choose 1 for Withdraw");
System.out.println("Choose 2 for Deposit");
System.out.println("Choose 3 for Check Balance");
System.out.println("Choose 4 for Exit");
System.out.print("Choose the operation you want to perform");
int n = s.nextInt();
switch(n)
{
case 1:
System.out.print("Enter money to be withdraw");
withdraw = s.nextInt();
if(balance >= withdraw)
{
balance = balance - withdraw;
System.out.println("Please collect your money");
}
else
{
System.out.println("Insufficient Balance");
}
System.out.println("");
break;

case 2:
System.out.print("Enter money to be deposited:");
deposit = s.nextInt();
balance = balance + deposit;
System.out.println("Your Money has been successfully deposited");
System.out.println("");
break;

case 3:
System.out.println("Balance : "+balance);
System.out.println("");
break;

case 4:
System.exit(0);
}
}
}
}

Welcome to State bank of india
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for Exit
Choose the operation you want to perform1
Enter money to be withdraw 455
Please collect your money

What is ATM and how it works

An automated teller machine (ATM) is an electronic banking terminal that enables consumers to conduct simple transactions without the assistance of a teller or branch personnel. At most ATMs, anyone with a credit or debit card can get cash.

Automated Teller Machines, or ATMs, are one of the most beneficial innovations in the banking industry. Customers can use ATMs to perform self-service operations such cash withdrawals, deposits, and fund transfers.

To conduct a transaction at an ATM, customers must use a plastic card—either a bank debit card or a credit card. Before any transaction can be completed, consumers must be validated using a PIN. A chip is found on many cards, and it transmits data from the card to the machine.

What is switch case and how it works

A switch statement allows a variable to be compared against a list of values for equality. Each value is referred to as a case, and each case is verified against the variable that is being turned on.

Java program to print the two digits of the year

Java program to print the two digits of the year. A Java program to extract the year’s last two digits. As an input, you can use any integer. The last two digits of the provided integer are then extracted as output using modulus and division operations. The source code for the Java Program to Extract the Last Two Digits of a Year can be found here.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int x, y, i = 0;
String z = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter the year");
x = s.nextInt();
while(i < 2)
{
y = x % 10;
z = y + "" +z;
x = x / 10;
i++;
}
System.out.println("Last two digits"+z);
}
}

Output:

Enter the year 1980
Last two digits 80

pre increment vs post increment in java programming

After utilising a variable in an expression, the post increment operator is used to increase its value. The value is used inside the expression and then incremented by one in the post increment. Both increase the value, but I does so before the current expression is evaluated, whereas i++ does so after the expression has been evaluated.

Write a java program to take a number and return list of its digits

Write a java program to take a number and return list of its digits. Take a number and return a list of its digits with a Java program. Take a number and return a list of its digits with a Java program.

As an input, you can use any integer number. The amount of digits in the given input is then counted. The given number, along with its length, is handed to the other function, which returns all of the digits of the given number via modulus and division operations.

import java.util.Scanner;
public class Main
{
int[] digits(int m,int l)
{
int x[] = new int[l];
int i = 0;
while(m > 0)
{
x[i] = m % 10;
m = m / 10;
i++;
}
return x;
}
public static void main(String[] args)
{
int counter = 0, n, m;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
m = n;
while(n > 0)
{
n =n / 10;
counter++;
}
Main obj=new Main();
int a[]=obj.digits(m, counter);
System.out.print("Digits:");
for(int i = a.length-1; i >= 0; i--)
{
System.out.print(a[i]+" ");
}
}
}

Output:

Enter any number: 45
Digits:4 5

What is while loop in java program and how it works

The while loop in Java is a control flow statement that allows code to be repeated based on a Boolean condition. The while loop is similar to a looping if statement. If the condition evaluates to true, the body of the loop will be executed, and we will proceed to the update expression.

Purpose of modulus operator in java program

The remainder of a division of one integer by another is returned by the modulus operator. Modulo is usually denoted by a percent sign in most programming languages. Because 2 divides into 4 precisely without a leftover, “4 mod 2” or “4 percent 2” returns 0

Post increament operator in java programming

After utilising variable in an expression, the post increment operator is used to increase its value. The value is used inside the expression and then incremented by one in the post increment.

Write a java program to check whether the given number is divisible by 5

Write a java program to check whether the given number is divisible by 5. Enter any integer as an input for this Java program to check if a given number is divisible by 5. To check the divisibility of a given integer by 5, we use the modulus operation.

If the given integer divides by 5 with zero as a remainder, it is divisible by 5; otherwise, it is not divisible by 5. source code for the Java Program to Check Whether a Number is Divisible by 5

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
if(n % 5 == 0)
{
System.out.println(n+" is divisible by 5");
}
else
{
System.out.println(n+" is not divisible by 5");
}
}
}

Output:

Enter any number:45
45 is divisible by 5

Division number in java program

Division is one of the four basic mathematical operations, with addition, subtraction, and multiplication being the other three. Simply said, division is the process of dividing a large group into equal smaller units.

What are the uses of modulo operator in java programming

After division, the Modulo or Remainder Operator returns the remainder of the two numbers. If you’re given two numbers, say A and B, where A is the dividend and B is the divisor, is there a residue of A and B’s division? The modulo operator is an arithmetic operator indicated by the letter percent.

Java program to print the number entered by the user using for loop

Java program to print the number entered by the user using for loop. This is a Java program that uses the For Loop to display numbers from 1 to 10.  We use a For Loop to set a variable to 1 and increment it by 1 each time until we reach 10. 

When variable 11 is reached, the loop ends. The Java Program to Display Numbers from 1 to 10 Using For Loop source code is available here.

public class Main
{
public static void main(String[] args)
{
for(int i = 1; i <= 10; i++)
{
System.out.println(i);
}
}
}

Output:

1
2
3
4
5
6
7
8
9
10

What is for loop and how it works

A for loop is a repetition control structure that allows you to design a loop that must be repeated a certain number of times quickly. When you know how many times a task will be repeated, a for loop comes in handy.

Write a program illustrate use of various boolean operators in java

Write a program illustrate use of various boolean operators in java. A Java program that demonstrates how to use various Boolean operators.As input, choose any two boolean values. Then, to get the desired output, we use various boolean bitwise operations such as AND, OR, XOR, and NOT. The source code for the Java Program to Demonstrate the Use of Various Boolean Operators can be found here.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.print("Enter a:");
boolean a = s.nextBoolean();
System.out.print("Enter b:");
boolean b = s.nextBoolean();
boolean c = a | b;
boolean d = a & b;
boolean e = a ^ b;
boolean f = (!a & b) | (a & !b);
boolean g = !a;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("a|b = " + c);
System.out.println("a&b = " + d);
System.out.println("a^b = " + e);
System.out.println("!a&b|a&!b = " + f);
System.out.println("!a = " + g);
}
}

Output:

Enter a:true
Enter b:false
a = true
b = false
a|b = true
a&b = false
a^b = true
!a&b|a&!b = true
!a = false

What is boolean operator in java programming

The primitive data type boolean accepts either “true” or “false” values. As a result, anything that returns the value “true” or “false” is a boolean example. Some circumstances, such as “a==b,” “ab,” or “a>b,” can be thought of as boolean examples.

Boolean Operators (AND, OR, NOT, or AND NOT) are basic words that are used as conjunctions to combine or exclude keywords in a search, resulting in more focused and productive results. This should save time and effort by removing irrelevant hits that would otherwise have to be scanned before being discarded.

What is operators in java program

Operators are a subset of functions that take one or more arguments and return a new value. Operators include things like addition (+), subtraction (-), multiplication (*), and so on. Variables and constants are operated on with the use of operators.

Java program to check whether entered character is uppercase or lowercase

Java program to check whether entered character is uppercase or lowercase. This is a Java program that determines whether the given Alphabets are Uppercase, Lowercase, or Digits. Any character can be used as input. After that, we compare the ASCII value of that character to the three cases provided.

If that value is the same, the output will be the same. The source code for the Java program to determine whether given Alphabets are Uppercase, Lowercase, or Digits is available here.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main
{
public static void main(String args[]) throws IOException
{
char m;
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter any letter");
m = (char) bf.read();
if(m >= 97 && m <= 123)
{
System.out.println("Lower Case");
}
else if(m >= 65 && m <= 96)
{
System.out.println("Upper Case");
}
else if(m >= 48 && m <= 57)
{
System.out.println("Number");
}
}
}

Output:

Enter any letter g
Lower Case

What is IOExpection in java program

IOException is a checked exception that must be handled correctly by the application developer. That means that if a file is not found when your programme is looking for it, an ileNotFoundException will be issued. IOException has a subtype called FileNotFoundException. 

To define an exception in Java, use the throws keyword. It informs the programmer that an exception may occur, hence it is preferable for the programmer to write exception handling code in order to maintain regular flow.

What is buffered reader in java program

The Java class BufferedReader consumes text from the input stream. It buffers the characters so that it may read characters, arrays, and other data efficiently. It inherits the reader class, which makes the code more efficient because the readline() method allows us to read the data line by line.

What is InputStreamReader program in java

An InputStreamReader is a converter between byte and character streams: It reads bytes and converts them to characters with the help of a charset. The charset it uses can be provided explicitly or by name, or the platform’s default charset can be allowed.

What is if else if program in java

The conditional statements in Java are as follows: If a particular condition is true, use if to specify a block of code to be run. If the same condition is false, use otherwise to specify a block of code to run. If the initial condition is false, use else if to define a new condition to test.

Write a java program to print the ip address

Write a java program to print the ip address. This is a Java program that displays the system’s IP address.An Internet Protocol address is represented by the InetAddress class. To get the IP address string in textual format, we use this class’s getHostAddress() method. Here is the source code for the Java programme that displays the system’s IP address.

import java.net.InetAddress;
public class Main
{
public static void main(String args[]) throws Exception
{
InetAddress IP = InetAddress.getLocalHost();
System.out.println("IP address= "+IP.getHostAddress());
}
}

Output:

IP address 000.000.000.000

What is IP address in computer

An IP address (Internet Protocol address) is numerical identification assigned to each device connected to computer network that communicates using the Internet Protocol. 
An IP address is used for two purposes: identifying host or network interface, and addressing specific location.

What is INET address in java program

The InetAddress class contains methods for obtaining the IP address of any host name, such as www.noteshippo.com, www.google.com, www.facebook.com, and so on. A 32-bit or 128-bit unsigned number is used to represent an IP address. The IP address and its accompanying host name are represented by an instance of InetAddress.

The Java InetAddress class’s getLocalHost() function returns an instance of InetAddress with the local host name and address. First, the system’s host name is retrieved, and then that name is resolved into InetAddress.

Write a java program to convert numbers into years, weeks and days

Write a java program to convert numbers into years, weeks and days. This Java program converts a given number of days to years, weeks, and days. As an input, choose any integer number.

Then, to calculate the number of years, we divide the input by 365. Then we divide by 7 to get the number of weeks using the modulus operation. To get the number of days, we use modulo operation.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int m, year, week, day;
Scanner s = new Scanner(System.in);
System.out.print("Enter the numbers");
m = s.nextInt();
year = m / 365;
m = m % 365;
System.out.println("No of years"+year);
week = m / 7;
m = m % 7;
System.out.println("No of weeks:"+week);
day = m;
System.out.println("No of days:"+day);
}
}

Output:

Enter the numbers567
No of years1
No of weeks:28
No of days:6

Why do we have 12 months and when it is created

The requirement for 12 months in a year and the addition of a leap year to coordinate with the seasons was explained by Julius Caesar’s astronomers. Because these months were named after Roman leaders, they were given 31 days to signify their importance.

Julius Caesar ordered a calendar with twelve months based on a solar year in 45 B.C. This calendar used a three-year cycle of 365 days, followed by a 366-day year (leap year). The “Julian Calendar” also shifted the start of the year from March 1 to January 1 when it was originally introduced.

What is util scanner in java program

Scanner is a class in the Java util package that is used to get input of primitive kinds such as int, double, and strings. It’s the simplest way to read input in a Java program, but it’s inefficient if you need an input method for situations where time is a factor, such as competitive programming.

Java program to print the number positions in list of digits

Java program to print the number positions in list of digits. This is a Java program for extracting digits from an integer value. As an input, you can use any integer.After that, we perform operations such as modulus and division to determine the number of digits in a given integer, and then we print each of the digits. The Java Program to Extract Digits from a Given Integer source code is available here.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int n, m, a, i = 1, checker = 0;
Scanner s=new Scanner(System.in);
System.out.print("Enter any numbers");
n = s.nextInt();
m = n;
while(n > 0)
{
n = n / 10;
checker++;
}
while(m > 0)
{
a = m % 10;
System.out.println("numbers position is "+checker+":"+a);
m = m / 10;
checker--;
}
}
}

Output:

Enter any numbers  4567
numbers position is 4:7
numbers position is 3:6
numbers position is 2:5
numbers position is 1:4

What is pre increment and post increment in java

Before assigning value to variable, the pre increment operator is used to increase its value by 1. After assigning value to variable, the post increment operator is used to increase its value by one.

While loop and how it works in java program

The condition is assessed first in a while loop, and if it returns true, the statements inside the while loop are executed. This process is repeated until the condition returns false. When the condition returns false, the control exits the while loop and moves on to the next sentence in the program.

Java program to increment by 1 all the digits of a given integer

Java program to increment by 1 all the digits of a given integer. This is a Java program that increments all of a given integer’s digits by one. As input, you may use any integer.

Following that, we extract each digit and increment it by one using various operations such as modulus and division. The Java Program to Increment All the Digits of a given Integer by 1 source code is available here.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, m = 0, a;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
while(n > 0)
{
a = n % 10;
a++;
m = m * 10 + a;
n = n / 10;
}
n = m;
m = 0;
while(n > 0)
{
a = n % 10;
m = m * 10 + a;
n = n / 10;
}
System.out.println("Output"+m);
}
}

Output:

Enter any number: 45

Output 56

What is while loop in java program

A “While” Loop is used to repeat a block of code an unknown number of times until it meets a condition. If we want a user to enter a number between 1 and 10, for example, we don’t know how many times the user might enter a larger number, so we keep asking “while the value is not between 1 and 10.”

What is pre increment and post increment in java program

The only difference is the order of operations between the variable’s increment and the value returned by the operator. I returns the value after it has been incremented, whereas i++ returns the value before it has been incremented. In the end, the value of I will be increased in both circumstances.

Both increase the value, but I does so before the current expression is evaluated, whereas i++ does so after the expression has been evaluated. Before assigning a value to a variable, the pre increment operator is used to increase the value by one. After assigning a value to a variable, the post increment operator is used to increase the value by one.

Write a java program to accept two numbers and check which is same or not

Write a java program to accept two numbers and check which is same or not. This is a Java program that accepts two integers and compares them to see if they’re equal. As input, enter two integer numbers.

After that, we use the equal to operator to match both inputs. As a result, the output is generated appropriately. The Java Program to accept Two Integers and check if they Are equal can be found here.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int m, n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the first number");
m = s.nextInt();
System.out.print("Enter the second number");
n = s.nextInt();
if(m == n)
{
System.out.println(m+" and "+n+" are same");
}
else
{
System.out.println(m+" and "+n+" are not same");
}
}
}

Output

Enter the first number34
Enter the second number43
34 and 43 are not same

If else statement in java program

For a single condition, the if-else statement is used to conduct two operations. The if-else statement is an expansion of the if statement that allows us to conduct two different operations, one for the condition’s correctness and the other for its incorrectness. It is important to note that the if and else blocks cannot be executed concurrently.

Scanner in java program

Scanner is a class in the Java util package that is used to get input of primitive kinds such as int, double, and strings. It’s the simplest way to read input in a Java program, but it’s not very efficient if you’re looking for an input method for situations where time is a factor, such as competitive programming.

Write a java program to find the reverse of a given number using recursion

Write a java program to find the reverse of a given number using recursion. This is a Java program that uses recursion to find the reverse of a number. As an input, you can use any integer number.

The amount of digits in the given input is then counted. The specified integer, together with its length, is sent to the other function, which returns the reverse of that number using recursion.

import static java.lang.StrictMath.pow;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, count = 0, m;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number");
n = s.nextInt();
m = n;
while(m > 0)
{
count++;
m = m / 10;
}
Main obj = new Main();
int a = obj.reverse(n, count);
System.out.println("Reverse"+a);
}
int reverse(int x, int length)
{
if(length == 1)
{
return x;
}
else
{
int b = x % 10;
x = x / 10;
return (int) ((b * pow(10, length - 1)) + reverse(x, --length));
}
}
}

Output:

Enter the number 45
Reverse 54

Why do we use recursion in java program

When a recursive function calls itself, memory for the called function is placed on top of memory for the calling function, and each function call creates a new copy of local variables. Let’s use a basic function as an example of how recursion works. Recursion is designed to solve issues that can be broken down into smaller, more repeatable ones. 

It’s especially useful for dealing with problems that have a lot of potential branches yet are too complex to be solved by iteration. Searching across a file system is a nice illustration of this. Recursion is designed to solve issues that can be broken down into smaller, more repeatable ones.

What is count() keyword in java program

The count() function in Java returns the number of elements in the stream. We can also use the Collectors. counting() function to count the number of elements in a stream. The method count() is a terminal operation.

Java program to find product of two numbers using recursive function

Java program to find product of two numbers using recursive function. This is a Java program that uses recursion to find the product of two numbers. As an input, enter two integer numbers. Then we feed the two specified numbers, along with zero, to the other function, which uses recursion to get numbers one by one to multiply. As a result, the output is the product of the two provided numbers.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int[] a = new int[2];
Scanner s = new Scanner(System.in);
System.out.print("Enter the first number");
a[0] = s.nextInt();
System.out.print("Enter the second number");
a[1] = s.nextInt();
Main obj = new Main();
int mul = obj.multiply(a,0);
System.out.println("Answer:"+mul);
}
int multiply(int x[], int i)
{
if(i < 2)
{
return x[i] * multiply(x, ++i);
}
else
{
return 1;
}
}
}

Enter the first number 45
Enter the second number 56
Answer: 2520

Recursion method in java program

In Java, recursion is the process of a method constantly calling itself. In Java, a recursive method refers to a method that calls itself.It compresses the code but makes it difficult to comprehend. When a recursive function calls itself, the called function’s memory is allocated on top of the calling function’s memory, and each function call creates a new copy of local variables

nextInt() method in java program

nextInt() is a method that returns an integer. As an int, scans the next token of the input. Invocations of this function with the form nextInt() behave precisely the same as invocations with the form nextInt(radix), where radix is the scanner’s default radix.

What is conditional operator in java program

Conditional statements assist you in making decision depending on set of circumstances. collection of conditional statements using boolean expressions that evaluate to true or false are used to specify these conditions.

Java program to swap two numbers using bitwise xor operator

Java program to swap two numbers using bitwise xor operator. The source code for a Java program that uses the Bitwise XOR operation to swap the contents of two numbers. As input, choose any two integer numbers. Then we discover the bitwise XOR of the first and second variables and store the result in the first variable. We repeat the bitwise XOR operation on the same variables and save the result in the second variable.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int m, n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the first number");
m = s.nextInt();
System.out.print("Enter the second number");
n = s.nextInt();
m = m ^ n;
n = m ^ n;
m = m ^ n;
System.out.println("After Swapping the number");
System.out.println("First number:"+m);
System.out.println("Second number:"+n);
}
}

Enter the first number 45
Enter the second number 56
After Swapping the number
First number: 56
Second number: 45

What is Bitwise operator in java and its uses

A bitwise operator is an operator that manipulates individual bits in bit patterns or binary numerals to execute bitwise operations. In communication stacks, where the individual bits in the header attached to the data represent crucial information, bitwise operators are utilized.

Checking if an integer is even or odd is another technique you can do using bitwise operators. Let’s see what we can come up with. The idea behind! is that the binary representation of 1 is 0001, and the least significant bit’s place value is 1.

Difference between bitwise operator and logical operator

To begin, logical operators operate on boolean expressions and return boolean values (true or false), whereas bitwise operators operate on binary digits of integer values (long, int, short, char, and byte) and return an integer value.

How bitwise operators are faster

It is a quick and simple action that is fundamental to higher-level arithmetic operations and is provided directly by the CPU.

Xor operator in java program

The exclusive or logical operation accepts two boolean operands and returns true only if and only if they are different. 
 
As result, if the two operands have the same value, it returns false. So, when we need to check for two conditions that can’t both be true at the same time, we can use the XOR operator.

Java program to find the sum of digits of a number using recursion function

Java program to find the sum of digits of a number using recursion function. The source code for a Java program that uses recursion to find the sum of a number’s digits. As an input, you can use any decimal number. Now we feed that number to a new function, where we utilise the modulo operator and recursion to determine the sum of digits as output.

import java.util.Scanner;
public class Main
{
int sum = 0;
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the numbers");
n = s.nextInt();
Main obj = new Main();
int a = obj.add(n);
System.out.println("Sum"+a);
}
int add(int n)
{
sum = n % 10;
if(n == 0)
{
return 0;
}
else
{
return sum + add(n / 10);
}

}
}

Enter the number:45
Sum:9

What is recursion function in java program

In computer science, recursion is a phenomena that is utilised to solve large problems by breaking them down into smaller ones. Recursion is the process through which a function directly or indirectly invokes itself.

Recursive function is the name given to the related function. Reduce the number of times a function is called unnecessarily. Recursion allows one to solve issues quickly, whereas the iterative solution is large and complex.

A recursive function is one that calls itself while it is being executed. The process may be repeated numerous times, with each iteration ending with the output of the result. Programmers can use recursive functions to develop efficient programmes with a small amount of code.

Purpose of recursion function in java program

Recursion is a problem- solving technique in which the solution is based on the solutions to smaller instances of the same problem. Iteration can usually handle such problems, but it requires identifying and indexing the smaller instances at programming time.

Write a c program to print hello world

Write a  C program to print the Hello world. You will learn how to print “Hello World” on the screen using C programming in this example. You should be familiar with the following C programming fundamentals in order to follow along with this example.

#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}

Hello World

How to execute the hello world program in c

The stdio.h file includes functions to take input and display output, such as scanf() and printf().

The application will not compile if you use the printf() method without include stdio.h. printf() is a library function that displays formatted output.

Printf() prints the text Hello World on the screen in this application.

What is header file in c program and its uses

A header file has the suffix. h and includes C function declarations and macro definitions that may be reused across several source files. The files that the programmer creates and the files that arrive with your compiler are the two sorts of header files.

A header file’s main function is to ensure that declarations are propagated to code files. We can put declarations in one place and then import them anywhere we need them via header files. In multi-file apps, this may save a lot of typing.

Java program to print two multiply binary numbers with solution

Java program to print two multiply binary numbers with a solution. A binary number is a number expressed in the base-2 numeral system, also known as the binary numeral system, in digital electronics and mathematics.

import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
long bin1, bin2, multiply = 0;
int digit, factor = 1;
Scanner in = new Scanner(System.in);
System.out.print("first bin number");
bin1 = in.nextLong();
System.out.print("second bin number");
bin2 = in.nextLong();
while (bin2 != 0)
{
digit = (int)(bin2 % 10);
if (digit == 1)
{
bin1 = bin1 * factor;
multiply = binproduct((int) bin1, (int) multiply);
}
else
{
bin1 = bin1 * factor;
}
bin2 = bin2 / 10;
factor = 10;
}
System.out.print("Product of two bin numbers: " + multiply+"\n");
}
static int binproduct(int bin1, int bin2)
{
int i = 0, remainder = 0;
int[] sum = new int[20];
int bin_prod_result = 0;

while (bin1 != 0 || bin2 != 0)
{
sum[i++] = (bin1 % 10 + bin2 % 10 + remainder) % 2;
remainder = (bin1 % 10 + bin2 % 10 + remainder) / 2;
bin1 = bin1 / 10;
bin2 = bin2 / 10;
}
if (remainder != 0)
{
sum[i++] = remainder;
}
--i;
while (i >= 0)
{
bin_prod_result = bin_prod_result * 10 + sum[i--];
}
return bin_prod_result;
}
}

first binary number: 110

second binary number: 101

Product of two binary numbers: 11110

What is binary number in java program

A binary number is made up of two digits: 0s and 1s. Binary numbers have a base of 2 and are represented as such. (101)2 ( 101 ) 2 is an example. A bit is a name given to each digit in a binary integer.

What is long keyword in java programming

A minimum value of -263 and a maximum value of 263-1 can be found in the long. Long can now be represented as an unsigned 64-bit long with a minimum value of 0 and a maximum value of 264-1 in Java 8. 0L is the default value. It has an 8-byte default size. It’s utilised when you need an integer value with a larger range.

Java program to print the upper case to lower case alphabets

Java program to print the upper case to lower case alphabets. Java software to convert uppercase to lowercase letters.

In Java programs, this program can convert or shift uppercase to lowercase. In contrast to capital letters, small letters are used (upper case). In contrast to small letters, capital letters are used (lower case).

import java.util.Scanner;
public class Main
{
public static void main(String[] input)
{
char ch;
int temp;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a single Character in Uppercase ");
ch = scan.next().charAt(0);
temp = (int) ch;
temp = temp + 32;
ch = (char) temp;
System.out.print("Character in Lowercase = " + ch);
}
}

Output:

Enter a single Character in Uppercase G                                                                                       

Character in Lowercase = g

What is Upper case letters

Uppercase letters (also known as capital letters) are letters that indicate the start of a sentence or the commencement of a proper noun. Uppercase letters are used to start sentences and for proper nouns as well. All letters that do not begin sentences are lowercase letters.

What is Lower case letters

Small letters are referred to as lowercase, as opposed to capital letters. The word yes, for example, is written entirely in lowercase letters, whereas the word YES is written entirely in uppercase letters.

Java program to conversion hexadecimal to decimal number

Java program to convert hexadecimal to decimal numbers. Java software to convert hexadecimal to decimal numbers. Referring to or using a scheme of numerical notation with a foundation of 16 rather than 10.

The octal numeral system, also known as oct, is a base8 numbering system that employs the digits 0 through 7.By grouping consecutive binary digits into groups of three, octal numerals can be generated from binary numerals. 

import java.util.Scanner;
public class Main
{
public static int hexadecimal(String s)
{
String digits = "dvbkdfvkjvs";
s = s.toUpperCase();
int val = 0;
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
int d = digits.indexOf(c);
val = 16*val + d;
}
return val;
}
public static void main(String args[])
{
String hexdecnum;
int decnum;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Hexadecimal Number");
hexdecnum = scan.nextLine();
decnum = hexadecimal(hexdecnum);
System.out.print("Decimal Number is " + decnum);
}
}

Output:

Enter Hexadecimal Number sdfsdfsdffsdf                                                                                          

Decimal Number is -286331153  

Hexadecimal value in java program

The hexadecimal (also known as base 16 or hex) numeral system is a positional numeral system that uses a radix (base) of 16 to represent integers in mathematics and computing. A nibble (or nybble) is 1/2 of a byte, and each hexadecimal digit represents four bits (binary digits).

Decimal value in java program

Decimals are a form of a number in Algebra that has a whole number and a fractional part separated by a decimal point. The decimal point is the dot that appears between the full number and the fractions section. A decimal number, for example, is 34.5.

Octal to hexadecimal conversion program in java

Octal to hexadecimal conversion program in java. In a Java program, convert an octal number to a hexadecimal number. This isn’t your typical octal to hexadecimal converter. The octal numeral system, also known as oct, is a base-8 numbering system that employs the digits 0 through 7.

By grouping consecutive binary digits into groups of three, octal numerals can be generated from binary numerals. Relating to or using a system of numerical notation with a foundation of 16 rather than 10. 

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
String octalnumber, hexadecimal;
int decimalnum;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Octal Number ");
octalnumber = scan.nextLine();
decimalnum = Integer.parseInt(octalnumber, 8);
hexadecimal = Integer.toHexString(decimalnum);
System.out.print("Hexadecimal Value of " + octalnumber + " is :\n");
System.out.print(hexadecimal);
}
}

Output:

Enter Octal Number : 56                                                                                                       

Equivalent Hexadecimal Value of 56 is :                                                                                       

2e 

Hexadecimal function in java program

The Hexadecimal Number System is a type of numerical representation with the number 16 as the base number. That means there are only 16 possible digit values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Only four bits are required to express the value of any digit.

Octal function in java program

The octal numeral system, sometimes known as oct, is a base-8 numbering system that use the numerals 0 through 7. By arranging consecutive binary digits into groups of three, octal numerals can be created from binary numerals (starting from the right). The binary representation of decimal 74, for example, is 1001010.

Java program to print hexadecimal to decimal number conversion

Java program to print hexadecimal to decimal number conversion. For beginners, a program to convert hexadecimal to decimal numbers in java and an explanation of how the conversion function works in the java programming language.

Referring to or using a scheme of numerical notation with a foundation of 16 rather than 10. A decimal number is known as a number with a decimal point separating the whole number and fractional parts. 

public class Main
{ 
public static void main(String args[])
{ 
System.out.println(Integer.parseInt("f",16)); 
}
}

Output
15

What is Hexadecimal number in java

The Hexadecimal Number System is a sort of numerical representation in which the base number is 16. That means there are only 16 potential digit values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Any digit’s value can be represented using only four bits.

What is Decimal number in java

Decimals are a form of a number in Algebra that has a whole number and a fractional part separated by a decimal point. The decimal point is the dot that appears between the full number and the fractions section. A decimal number, for example, is 34.5.

Parse function in java

Converting data in the String format from a file, human input, or a network is known as parsing String in Java. Parsing a String is the process of extracting data from it in a String format. A String can be transformed to an array using the Split method by giving the delimiter to the split method.

Java program to print decimal to octal conversion

Java program to print decimal to octal conversion. In a Java program, convert decimal to octal. Decimals are one of the types of numbers since a decimal point distinguishes the whole number from the fractional variable.

The octal numeral system, also known as oct, is a base-8 numbering system that employs the digits 0 through 7. By grouping consecutive binary digits into groups of three, octal numerals can be generated from binary numerals.

public class Main
{ 
public static void main(String args[])
{ 
System.out.println(Integer.toOctalString(15)); 
}
} 

Output

17

What is octal number in java

The octal numeral system, sometimes known as oct, is a base-8 numbering system that uses the numerals 0 through 7. By arranging consecutive binary digits into groups of three, octal numerals can be created from binary numerals.

Using octal to abbreviate binary numbers is a convenient technique to do so. Begin by grouping all binary digits into groups of three, starting on the right.

What is decimal number in java

A decimal number is defined as a number with a decimal point separating the full number and fractional parts. The digits after the decimal point represent a value less than one.

The tenths place is represented by the first digit following the decimal. The hundredths place is represented by the following digit after the decimal. The remaining digits fill in the place values until there are no more digits to put in.

Java program to print decimal number to binary

Java program to print decimal number to binary. In Java, convert a decimal number to a binary number. A decimal point separates the entire number from the fractional component, making decimals one of the forms of numbers. 

A binary number is a number represented in the base-2 numeral system or binary numeral system,which uses only two symbols: commonly “0” and “1” in mathematics and digital electronics.

public class Main
{ 
public static void main(String args[])
{ 
System.out.println(Integer.toBinaryString(5)); 
}
}

Output:

101

What is toBinaryString function in java program

The toBinaryString() method in java. lang. The integer package returns a string representation of the integer input as an unsigned integer in base 2. It takes an Int data-type argument and returns a binary string in return.

What is decimal value in java

A decimal number is defined as a number with a decimal point separating the full number and fractional parts. A decimal point is a dot in a decimal number. The digits after the decimal point represent a value less than one.

What is integer value in java

Integer, positive or negative whole-valued number, or 0. The integers are created using the counting numbers 1, 2, and 3 as well as the subtraction process. When you subtract a counting number from itself, the result is zero; for example, 4 4 = 0.

Java program to print ASCII value of all alphabets

Java program to print ascii value of all alphabets. In the Java programming language, print the Ascii value.In the programming language, each letter has an ASCII value to print.

The American Standard Code for Information Interchange, or ASCII, is a character encoding standard used in electronic communication. In computers, telecommunications equipment, and other devices, ASCII codes represent text.

public class Main
{
public static void main(String args[])
{
String Letter;
int i;
for(i=1; i<=255; i++)
{
Letter = new Character((char)i).toString();
System.out.print(i+ " -> " + Letter + "\t");
}
}
}

Output:

253 -> ý 254 -> þ        255 -> ÿ

What is ASCII value and how to find the ascii value

The American Standard Code for Information Interchange (ASCII) is the full version of ASCII. It’s a character encoding system that’s commonly used in electronic communication. Each ASCII code represents a character or a special character, and each ASCII code takes up 7 bits in memory.

Who invented ASCII value

Telegraph coding was used to create ASCII. Bell data services promoted it as a seven-bit teleprinter code, which was its first commercial application. The first meeting of the American Standards Association’s ASCII Committee took place in May 1961.

What is string function in java

In computer programming languages, string functions are used to edit a string or obtain information about a string. Most programming languages with a string datatype will contain string functions, while there may be additional low-level ways to handle strings directly within each language.

Write a java program to print the length and perimeter of a rectangle

Write a java program to print the length and perimeter of a rectangle. In a Java program, measure the length and breadth.The region and perimeter will be printed in the java program’s output.

The length and width of the input will be printed as a field and perimeter in the output. The term “length” refers to how long something is, or how much vertical space or time it occupies. A closed geometrical figure’s boundary is defined as a continuous line.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int length, breadth, peri, area;
Scanner scan = new Scanner(System.in);
System.out.print("Enter length and breadth of Rectangle ");
length = scan.nextInt();
breadth = scan.nextInt();
area = length*breadth;
peri = (2*length) + (2*breadth);
System.out.print("Area = " +area);
System.out.print("\nPerimeter = " +peri);
}
}

Output:

Enter length and breadth of Rectangle 34                                                                                        
56                                                                                                                              
Area = 1904                                                                                                                     
Perimeter = 180

How to calculate value of length and perimeter of rectangle

The perimeter of a rectangle is the sum of the lengths of all its sides. As a result, we can calculate the perimeter of a rectangle by adding all four sides. The specified rectangle’s perimeter is a + b + a + b.

What is length and how to calculate length

A rectangle has two sides: length (L) and width (W) (W). The longest side of a rectangle is the length, while the shortest side is the width. The breadth of a rectangle is another term for its width (b).

What is perimeter and how to calculate

The perimeter of a shape is the distance around its edge. Learn how to calculate the perimeter of various forms by adding up the side lengths.

Java program to print the area of circumference of a circle

Java program to print the area of the circumference of a circle. This Java program will print the Area Circumference of a Circle. The diameter of a circle is the distance around it in geometry. That is, the circumference is equal to the circle’s diameter.

Pi times the radius of the circle squared is the area of a circle. The circumference of a circle is the distance around it in geometry. That is, the circumference is equal to the circle’s diameter. The radius of a circle squared is pi 3.14 times the area of the circle.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
float r;
double area, circumstances;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Radius of Circle ");
r = scan.nextFloat();
area = 3.14*r*r;
circumstances = 2*3.14*r;
System.out.print("Area of Circle = " +area);
System.out.print("\ncircumstance of Circle = " +circumstances);
}
}

Output:

Enter Radius of Circle 5                                                                                                        

Area of Circle = 78.5                                                                                                           

circumstance of Circle = 31.400000000000002

What is float value in java

The float keyword in Java refers to a primitive data type. It’s a 32-bit IEEE 754 floating-point with single precision. It’s where variables and methods are declared. It is used to represent fractional numbers.

Difference between float and double value in java

Both the Double and the Float are used to represent decimal numbers, albeit in slightly different ways. When you multiply pi by 1000, both Double and Float sacrifice some precision after the comma. This means that Float has just four decimal places, but Double has twelve.

How to calculate the area of circumference of circle in java

It’s as simple as this: C = d. The circumference of the circle is represented by “C,” and the diameter is represented by “d.” That is, multiplying the diameter by pi will give you the circumference of a circle.

Java program to find HCF and LCM of two numbers

Java program to find HCF and LCM of two numbers. In the java program, find HCF and LCM; it will print the HCF and LCM numbers in the output of the user-entered number.The HCF of given numbers is the largest or greatest factor common to any two or more given natural numbers.When you multiply a number by a whole number, you get a multiple (greater than 0).

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int a, b, x, y, t, hcf, lcm;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Two Numbers");
x = scan.nextInt();
y = scan.nextInt();
a = x;
b = y;
while(b != 0)
{
t = b;
b = a%b;
a = t;
}
hcf = a;
lcm = (x*y)/hcf;
System.out.print("HCF = " +hcf);
System.out.print("\nLCM = " +lcm);
}
}

Output:
Enter Two Numbers45                                                                                                           
56                                                                                                                            
HCF = 1                                                                                                                       
LCM = 2520

Difference between HCF and LCM

Highest Common Factor
The greatest factor that is common to any two or more given natural numbers is known as the highest common factor (HCF). GCD is another name for GCD (Greatest Common Divisor). For example, the HCF of 8 is 8, while the HCF of 40 is 8.

Least Common Multiple

The LCM is an abbreviation for “least common multiple.” When you multiply a number by a whole number, you obtain a multiple (greater than 0). The smallest number that is a multiple of all the numbers in a group is called the Least Common Multiple (LCM). For example, the LCM of 16 and 20 is 80, which is the smallest number that is a multiple of both 16 and 20.

Applications of LCM and HCF in mathematics

What are the uses of LCM and HCF? To break things down into smaller chunks. Any number of sets of items should be evenly distributed into their largest grouping. To determine the number of persons we can invite.

Significance of HCF and LCM

The biggest factor present between two or more numbers is defined by the H.C.F., whereas the least number that is exactly divisible by two or more numbers is defined by the L.C.M. The greatest common factor (GCF) is also known as the greatest common factor (HCF), while the least common divisor (LCM) is also known as the least common divisor.

Write a java program to convert temperature from Celsius to Fahrenheit

Write a java program to convert temperature from Celsius to Fahrenheit. The Celsius scale is a measurement of temperature. It’s a measurement of how hot or cold something is.°C is a popular abbreviation. Water freezes at 32°F and boils at 212°F under normal conditions, denoting a temperature scale on which water freezes at 32°F and boils at 100°F.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
float cen;
double fah;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Temperature in Cen");
cen = scan.nextFloat();
fah = (1.8*cen) + 32;
System.out.print("Equivalent Temperature is" + fah);
}
}

Output:
Enter Temperature in Centigrade : 45                                                                                          
Equivalent Temperature in Fahrenheit = 113.0 

What is celsius and how to calculate it

The Celsius scale, often known as centigrade, is based on the freezing point and boiling point of water being 0° and 100°, respectively. It is commonly referred to as the centigrade scale because of the 100-degree difference between the specified values. Anders Celsius, a Swedish astronomer, created it in 1742.

Fahrenheit and it calculation methods

Relating to or containing a temperature scale in which water’s boiling point is 212°F and its freezing point is 32°F The Fahrenheit scale is used to measure temperature and is based on the freezing and boiling temperatures of water. At 32 degrees Fahrenheit, water freezes and boils at 212 degrees Fahrenheit. This is a scale that determines how hot or cold something is 11

Floating and Double keyword in java

Float

The abbreviation for “floating point” is “float.” According to the specification, it’s a built-in data type for describing numeric values with floating decimal points. The data type float is supported by C, C++, C#, and a number of other programming languages. Two additional common data types are integer and double.

Double

The double keyword is a basic data type in Java. It’s a double-precision 64-bit IEEE 754 floating-point. Variables and methods are declared here. In general, it is used to represent decimal numbers.

Write a java program to convert temperature from Fahrenheit to celsius degree

Write a java program to convert temperature from Fahrenheit to celsius degree. The Celsius scale is a measurement of temperature.

It’s a measurement of how hot or cold something is.°C is a popular abbreviation. Water freezes at 32°F and boils at 212°F under normal conditions, denoting a temperature scale on which water freezes at 32°F and boils at 100°F.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
float Fahrenheit;
double Celsius;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Temperature in Fahrenheit : ");
Fahrenheit = scan.nextFloat();
Celsius = (Fahrenheit-32) / 1.8;
System.out.print("Equivalent Temperature in Celsius = " + Celsius);
}
}

Output:
Enter Temperature in Fahrenheit : 103                                                                                         
Equivalent Temperature in Celsius = 39.44444444444444 

What is fahrenheit and how to find the fahrenheit temperature

pertaining to or possessing a temperature scale in which the boiling point of water is 212 degrees above zero and the freezing point is 32 degrees above zero.

The Fahrenheit scale is based on the freezing and boiling temperatures of water and is used to measure temperature. 

Water freezes at 32 degrees Fahrenheit and boils at 212 degrees. This is a measure for assessing how hot or cold something is. 11

What is celsius and how to calculate it

The Celsius scale, commonly known as centigrade, is based on the freezing point of water being 0° and the boiling point of water being 100°. 

Because of the 100-degree difference between the stated points, it is frequently referred to as the centigrade scale. It was invented in 1742 by Swedish astronomer Anders Celsius.

What is floating and double in this program

Float

The word “floating point” is abbreviated as “float.” It’s a built-in data type that’s used to describe numeric values with floating decimal points, according to the specification. Float is a data type that is recognized by C, C++, C#, and many other computer languages. Integer and double are two more popular data types.

Double

A primitive data type in Java is the double keyword. It’s a 64-bit IEEE 754 floating-point with double precision. It’s where variables and methods are declared. It is used to represent decimal numbers in general.

Print the sum of the natural numbers program in java using for loop

Print the sum of the natural numbers program in java using for loop. In a Java program, find the sum of n numbers. 

It will print the addition of n numbers in the java programming language for beginners, as well as the addition of a user-entered number. 

The result or answer we get when we add two or more numbers or words is known as sum.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int i, n, sum=0, num;
Scanner scan = new Scanner(System.in);
System.out.print("How many numbers you want to add");
n = scan.nextInt();
System.out.print("Enter " +n+ " number");
for(i=0; i<n; i++)
{
num = scan.nextInt();
sum = sum + num;
}
System.out.print("Sum of all " +n+ " numbers are " +sum);
}
}

Output
How many numbers you want to add5 
Enter 5 number
45                                                                   
56                                                                                       
78                                                                                               
34       
89 
Sum of all 5 numbers are 302 

What is natural numbers and not natural numbers in java

Natural numbers

The counting numbers 1, 2, 3,… are generally referred to as natural numbers; however, some definitions include 0, making the non-negative integers 0 through 1, 2, 3,… natural numbers as well. Whole numbers are natural numbers that include 0 as well.

Nonnatural numbers

Imaginary numbers, such as the square root of -1, are numbers that cannot be quantified. The number I can be used in formulae and equations, but it is not a real number that can be utilized in fundamental arithmetic. 

You can’t multiply or divide imaginary numbers. Infinity is another example of an imaginary number.

What is nextint() in java

nextInt() is a method that returns an integer. As an int scans the next token of the input. The invocation of this function with the form nextInt() acts precisely like the call nextInt, where radix is the scanner’s default radix.

Write a java program to print multiplication table using for loop

Write a java program to print multiplication table using for loop. In the Java application, print the mathematics tables. As a novice in the Java programming language, this software is even more impressive and expands the programming ideas. 

The method of obtaining a product by combining matrices, vectors, or other quantities according to particular laws.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int number, i, tab;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a numbers");
number = scan.nextInt();
System.out.print("Table of " + number + " is\n");
for(i=1; i<=5; i++)
{
tab = number*i;
System.out.print(number + " * " + i + " = " + tab + "\n");
}
}
}

Output:

Enter a numbers2
Table of 2 is
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10

For loop program to print the multiplication in java

A for loop is a repetition control structure that allows you to construct a loop that must be repeated a certain number of times quickly. 

When you know how many times a task will be repeated, a for loop comes in handy. A “For” Loop is used to repeat a block of code for a certain number of times. 

If we wish to verify every student’s grade in the class, for example, we loop from 1 to that number.

Scanner program in java to receive the multplication

The scanner is a class in the Java util package that is used to get the input of primitive kinds such as int, double, and strings.

It’s the simplest way to read input in a Java program, but it’s inefficient if you need an input method for situations where speed is a factor, such as competitive programming.

Java program to calculate percentage and average

Java program to calculate percentage and average. The Java program Percentage and Average can assist beginners in understanding the mathematics concept and how it works in the java programming language. 

A percentage is a number or ratio expressed as a fraction of 100 in mathematics (from Latin per centum “by a hundred”). 

The mode, or median, is a number that expresses the central or typical value in a collection of data.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int mark[] = new int[6];
int i;
float sum=0;
float average, percentage;
Scanner scan = new Scanner(System.in);
System.out.print("Enter your marks ");
for(i=0; i<6; i++)
{
mark[i] = scan.nextInt();
sum = sum + mark[i];
}
average = sum/6;
percentage = (sum/600) * 100;
System.out.print("Average= " +average);
System.out.print("\npercentage= " +percentage+ "%");
}
}

Output:
Enter your marks 45                                                                                                            67                                                                                                                              
78                                                                                                                              
13                                                                                                                              
54                                                                                                                              
67                                                                                                                              
Average= 54.0                                                                                                                   
Percentage= 54.000004%

What is percentage in general and java program

A percent is a ratio with 100 as the second word. The term “percent” refers to the number of pieces per hundred. The word per centum is derived from the Latin phrase per centum, which means hundred. 

The sign percent is used in mathematics to represent percent. A tenth of a whole is one percent. As a result, it may be expressed as both a decimal and a fraction.

Simply divide a percentage by 100 to convert it to a decimal. For instance, 50% becomes 0.5, 20% becomes 0.2, and 1% becomes 0.01.

What is average in java program

The terms average, mean, median, and norm all refer to a position in the middle. The quotient generated by dividing the total of a collection of figures by the number of figures is known as the average.

The mean may be the basic average or it may indicate a figure in the middle of two extremes if you scored an average of 85 on exams.

Java program for a calculator using switch case

Java program for a calculator using switch case. In Java programming, build a simple calculator program. This is a straightforward calculator. Basic operations such as add, sub, mul, and div will be performed. 

The java basic calculator software is intended only for beginners who want to learn how to use the java programming language to perform calculations. 

It is self-evident that a calculator can relieve the consumer of the need to perform mental calculations and rely on paper

import java.util.Scanner;
public class Main
{
public static void main(String[] args) 
{
Scanner reader = new Scanner(System.in);
System.out.print("Enter two numbers");
double first = reader.nextDouble();
double second = reader.nextDouble();
System.out.print("Enter an operators");
char operator = reader.next().charAt(0);
double result;
switch(operator)
{
case '+':
result = first + second;
break;
case '-':
result = first - second;
break;
case '*':
result = first * second;
break;
case '/':
result = first / second;
break;
default:
System.out.printf("operator is correct");
return;
}
System.out.printf("%.1f %c %.1f = %.1f", first, operator, second, result);
}
}

Output

Enter two numbers

4 5 9

What is switch case and uses of the switch case in java

In Java, the switch case is used to pick one of the multiple code blocks to execute. The control breaks out of the switch block when java reaches the break keyword. 

When this keyword is encountered, code execution is halted, and case testing within the block is completed after a match is discovered. No. Because a case must be a constant expression, this is not feasible. 

The major advantages of employing a switch are that it improves clarity by avoiding otherwise repeated coding and, in many situations, allows for quicker execution through simpler compiler optimization. A switch must include at least 257 case statements, according to Standard C.

Default

Access modifiers are a Java default keyword. By default, if you don’t apply any access modifiers to variables, methods, constructors, or classes, the default access modifier is used.

Break

There are two uses for the break statement in the Java programming language. When a break statement is reached within a loop, the loop is instantly stopped, and program control is resumed at the next statement after the loop.

Return

The control of the program is returned to the method’s caller when a return statement is used. Every Java method declares a return type, which is required for all Java methods. A primitive type, such as int, float, or double, a reference type, or a void type, can be used as a return type.

Java program to find Armstrong number using while loop

Java program to find Armstrong number using while loop. In the java programming language, check whether the number is an armstrong number or not. 

This software will determine whether or not the number is an armstrong number. To print the armstrong number in the output of a java program for beginners.

public class Main
{ 
public static void main(String[] args) 
{ 
int d=0,arm,temp; 
int n=154;
temp=n; 
while(n>0) 
{ 
arm=n%10; 
n=n/10; 
d=d+(arm*arm*arm); 
} 
if(temp==d) 
System.out.println("armstrong number"); 
else 
System.out.println("Not armstrong number"); 
} 
}

Output:

154 Not armstrong number

What is while loop and its uses in the armstrong number program

The while loop in Java is a control flow statement that allows code to be repeated based on a Boolean condition. The while loop is similar to a looping if statement. 

If the condition evaluates to true, the body of the loop will be executed, and we will proceed to the update expression. The condition is assessed first in a while loop, and if it returns true, the statements inside the while loop are executed.

This process is continued until the condition returns false. When the condition returns false, the control exits the while loop and moves on to the next sentence in the program.

Armstrong number program using temporary variable in java

A temporary variable is a variable in computer programming that has a limited lifetime and is used to retain data that will be deleted shortly or before it can be stored in a more permanent memory location.

It’s generally stated as a local variable, or a variable with a local scope because it’s short-lived. A temporary variable is a variable in computer programming that has a limited lifetime and is used to retain data that will be deleted shortly or before it can be stored in a more permanent memory location. 

It’s generally stated as a local variable, or a variable with a local scope because it’s short-lived.

Program to check whether the number is prime or not in java

Program to check whether the number is prime or not in java. In the Java programming language, you can choose whether to program in prime or not prime mode. 

For new learn beginners in the java programming language, this tutorial will show you how to verify if a number is a prime number or not in a java program. A single-digit number and 1 (e.g. 2, 3, 5, 7, 11)

public class Main 
{
public static void main(String[] args) 
{
int num = 100;
boolean flag = false;
for (int i = 2; i <= num / 2; ++i) 
{
if (num % i == 0) {
flag = true;
break;
}
}
if (!flag)
System.out.println(num + " is a prime number");
else
System.out.println(num + " is not a prime number");
}
}

Output:

100 is not a prime number

What is flag and boolean function in java

In programming, the flag variable is used as a signal to inform the computer that a specific condition has been satisfied. It’s generally used as a boolean variable, showing whether a condition is true or false.

What is boolean function in java to print the prime number

The Java Boolean class’s equals() function returns a Boolean result. If the argument is not null and is a Boolean object with the same Boolean value as this object, it returns true; otherwise, it returns false.

What is prime number and how to find the prime easily in java

A prime number is a number higher than one that has just two factors: itself and one. A prime number cannot be divided by another prime number without a remainder. The number 13 is an example of a prime number.

To determine whether a number is a prime number, divide it by two and see if the result is a whole number. It can’t be a prime number if you do. If you still don’t have a full number, divide it by prime numbers: 3, 5, 7, 11, and so on, always dividing by a prime number and so on.

Now, increment N by 1 in each iteration until that variable does not equally true, and check whether it is prime or not. 

If it’s prime, print it and set the discovered variable’s value to True. Otherwise, repeat the loop until the next prime number is found.

Palindrome string program in java using scanner

Palindrome string program in java using a scanner. Learn how to write a program to print palindrome or not in java using letters. 

In the Java programming language, you can make a palindrome or not. The topic of this program is whether or not the word is a palindrome. 

Madam, Malayalam. mam is a title, phrase, or sequence that reads the same backward as forwards.

import java.util.*;

class Main { public static void main(String args[]) { String a, b = ""; Scanner in = new Scanner(System.in); System.out.println("Enter the string"); a = in.nextLine(); int length = a.length(); for (int i = length - 1; i >= 0; i--) b = b + a.charAt(i); if(a.equals(b)) System.out.println("The string is a palindrome."); else System.out.println("The string is not a palindrome."); } }

Enter a string

maam

the string is a palindrome

What is palindrome number in java and its formula

In Java, a palindrome number is a number that is the same after being reversed. Palindrome numbers include 545, 343, 171, and 48984. 

It might also be a string such as LOL, MADAM, and so on. The next number in the Fibonacci sequence is the sum of the preceding two numbers, for example, 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, and so on. 0 and 1 are the first two numbers in the Fibonacci sequence.

In Java, there are two approaches to create a Fibonacci series program: Fibonacci Series without Recursion and Fibonacci Series with Recursion. 

Setting F0 = 0, F1 = 1, and then applying the recursive algorithm yields the Fibonacci numbers. Fn is equal to the sum of Fn-1 and Fn-2.

What is for loop in string program in java

A string is a collection of characters that are separated by quotation marks. All of the methods that a string object can call are listed on this reference page. 

To concatenate two strings, for example, use the join() function. Methods for searching strings. A for loop is a repetition control structure that allows you to construct a loop that must be repeated a certain number of times quickly.

Write a program to find factorial of a number using for loop in java

Write a program to find factorial of a number using for loop in java. In this program you will learn how to write a program to print factorial number or not program in java using for loop. 

In the Java programming language, program a factorial number or not. This is a simple program that determines whether a number is factorial or not. 

public class Main
{
public static void main(String[] args)
{
int num = 15;
long factorial = 1;
for(int i = 1; i <= num; ++i)
{
factorial = factorial * i;
}
System.out.printf("Factorial of %d is", factorial);
}
}

Output:

Factorial of 15 is 1307674368000

What is long keyword and its explaination in java

A minimum value of -263 and a maximum value of 263-1 may be found in the long. Long may now be represented as an unsigned 64-bit long with a minimum value of 0 and a maximum value of 264-1 in Java 8. 

0L is the default value. It has an 8-byte default size. It’s utilised when you require an integer value with a larger range.

What is factorial number and how to find the factorial numer in java

The product of all positive integers less than or equal to a particular positive integer, represented by that integer and an exclamation point in mathematics. 

As a result, factorial seven is expressed as 7!, which means 1 2 3 4 5 6 7. The factorial zero is equal to one. 

To get the factorial of a number, multiply it by the preceding number’s factorial value. For instance, to understand the value of 6! 720 is obtained by multiplying 120  by 6. For seven!

Write a program to print first ten natural numbers in java

Write a program to print first ten natural numbers in java. In this program you will learn how to write a program to sum of the natural numbers in java for beginners. In Java programming language, the sum of natural numbers. 

In the Java programming language, this is an example of a simple set program. The sum of natural numbers program is essentially an addition program that is run in a for loop

public class Main
{
public static void main(String[] args)
{
int number = 10, sum = 0;
for(int i = 1; i <= number; ++i)
{
sum =sum + i;
}
System.out.println("Sum = " + sum);
}
}

Output:

Sum = 55   

What is for loop and how it works

A for-loop is a control flow statement in computer science that specifies iteration and allows code to be performed repeatedly.

When the number of iterations is known before entering the loop, for-loops are commonly employed. The startup of the loop, when we set our counter to a beginning value. 

Before the loop starts, the initialization statement is executed. The test statement determines whether or not a particular condition is true.

What is natural number in java

Natural numbers are a subset of the number system that encompasses all positive integers from 1 to infinity and are used for counting.

 It does not include the number zero (0). 1,2,3,4,5,6,7,8,9,… are also known as counting numbers.

Natural numbers are a subset of real numbers, which only contain positive integers such as 1, 2, 3, 4,5, and 6, as well as zero, fractions, decimals, and negative numbers.

Java program to find largest of three numbers using nested if

Java program to find largest of three numbers using nested if. In java programming for beginners, the largest number program compares numbers to select the largest number in a given number. This program will check the which is largest number among these three.

public class Main
{
public static void main(String[] args)
{
double a = 500, b = 1000, c = 1500;
if( a >= b && a >= c)
System.out.println(a + " largest number");
else if (b >= a &am