Program to print the largest element in an array17 Mar 2025 | 2 min read In this program, we need to find out the largest element present in the array and display it. This can be accomplished by looping through the array from start to end by comparing max with all the elements of an array. If any of element is greater than max, then store a value of the element in max. Initially, max will hold the value of the first element. At the end of the loop, max represents the largest element in the array. ![]() In the above array, initially, max will hold the value 25. In the 1st iteration, max will be compared with 11, since 11 is less than max. Max will retain its value. In the next iteration, it will be compared to 7, 7 is also less than max, no change will be made to the max. Now, max will be compared to 75. 75 is greater than max so that max will hold the value of 75. Continue this process until the end of the array is reached. At the end of the loop, max will hold the largest element in the array. Algorithm
Program:Output: Largest element present in given array: 75 Next TopicJava Programs |
File: CharacterPercentage .java import java.text.DecimalFormat; public class CharacterPercentage { static void charPercentage(String input) { int totalChar = input.length(); int upperCase = 0; int lowerCase = 0; int digits = 0; int others = 0; for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); if (Character.isUpperCase(ch)) { upperCase++; } else if (Character.isLowerCase(ch)) { lowerCase++; } else...
1 min read
Binary search is used to search a key element from multiple elements. Binary search is faster than linear search. In case of binary search, array elements must be in ascending order. If you have unsorted array, you can sort the array using Arrays.sort(arr) method. Binary Search Algorithm...
8 min read
It is a very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going...
3 min read
Java String to long We can convert String to long in java using Long.parseLong() method. Scenario It is generally used if we have to perform mathematical operations on the string that contains long number. Whenever we get data from textfield or textarea, entered data is received as a string....
1 min read
Java program to print the following pattern Algorithm: STEP 1: START STEP 2: SET i=1,j=1,k=1,l=1,direction=1 STEP 3: SET matrix[5][5] STEP 4: REPEAT STEP 5 to 9 UNTIL i is less than 5 STEP 5: SET j=0 STEP 6: REPEAT STEP 7 and 8 UNTIL j is less than 5 STEP 7: SET matrix[i][j]=0 STEP...
11 min read
In this program, we will create a singly linked list and add a new node at the beginning of the list. To accomplish this task, we will store head to a temporary node temp. Make newly added node as the new head of the list....
5 min read
In this program, we need to remove the duplicate nodes from the given singly linked list. Original List: List after removing duplicate nodes: In the above list, node 2 is repeated thrice, and node 1 is repeated twice. Node current will point to head, and index will point...
7 min read
Multiplication of matrix is a core concept in programming. We can perform matrix multiplication in Java using a simple nested for loop approach to advance approach. The nested for loop approach has a time complexity of O(n3). The time complexity of matrix multiplication can be improved...
17 min read
Java Convert int to char We can convert int to char in java using typecasting. To convert higher data type into lower, we need to perform typecasting. Here, the ASCII character of integer value will be stored in the char variable. To get the actual value in char...
2 min read
In this program, we need to search a given node in a doubly linked list. To solve this problem, we will traverse through the list using a node current. Current points to head and start comparing searched node data with current node data. If they are...
5 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India