Search Element in Array Java

Search Element in Array Java Program for beginner. A data structure called an array comprises a collection of elements, values, or variables, each of which is identifiable by an array index or key. Array types, depending on the language, may overlap or be mistaken with other data types that express collections of items, such as lists and strings.

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

int[] num = {10, 20, 30, 40, 50, 13};
int toFind = 13;
boolean found = false;
for (int n : num)
{
if (n == toFind)
{
found = true;
break;
}
}
if(found)
System.out.println(toFind + " is found");
else
System.out.println(toFind + " is not found");
}
}

 

Output:

13 is found

What is Boolean in Java

The boolean keyword is a primitive data type in Java. It can only store one of two potential values: true or false. With variables and methods, the boolean keyword is utilised. False is the default setting. It’s usually used in conjunction with conditional statements. In this program  we can Search Element in Array Java.

What is Decision Making Statement in Java

Decision Making in Java facilitates the creation of decision-driven statements and the execution of a specific set of code in response to specified situations. If a condition is true, the if statement will execute a block of statements; if the condition is false, the if statement will not.

Search Element in Array Java For Beginner

In Java, an array is a collection of variables that are referred to by a single variable name and an index number. An array’s items are called elements. An array’s items must all be of the same type. As a result, the array has a type that determines the types of elements it can hold.

Similar Programs