- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 74 Articles for Java Technologies
8K+ Views
The * operator in Java is used to multiply two numbers. Read required numbers from the user using Scanner class and multiply these two integers using the * operator.Exampleimport java.util.Scanner; public class MultiplicationOfTwoNumbers { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter the value of the first number ::"); int a = sc.nextInt(); System.out.println("Enter the value of the first number ::"); int b = sc.nextInt(); int result = a*b; System.out.println("Product of the given two numbers ... Read More
778 Views
Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function. You can reverse a string using the recursive function as shown in the following program.ExampleLive Demopublic class StringReverse { public String reverseString(String str){ if(str.isEmpty()){ return str; } else { return reverseString(str.substring(1))+str.charAt(0); } } public static void main(String[] args) { StringReverse obj = new StringReverse(); String result = obj.reverseString("Tutorialspoint"); System.out.println(result); } }OutputtniopslairotuT
3K+ Views
You can read data from the user using scanner class.Using the nextInt() method of this class get the number of elements from the user.Create an empty array.Store the elements entered by the user in the array created above.Finally, Add all the elements in the array and divide the sub by the number of elements.Exampleimport java.util.Scanner; public class AverageUsingArrays { public static void main(String args[]){ //Reading total no.of elements Scanner sc = new Scanner(System.in); System.out.println("Enter the number of elements/numbers"); int num = sc.nextInt(); ... Read More
953 Views
In the loop check, the result of I %2 operation on each element, if 0 the element is even else the element is odd.ExampleLive Demopublic class OddNumbersInAnArray { public static void main(String args[]){ int[] myArray = {23, 93, 56, 92, 39}; System.out.println("Even numbers in the given array are:: "); for (int i=0; i
8K+ Views
To find the 2nd smallest element of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the 2nd element of the array.ExampleLive Demopublic class SmallestNumberInAnArray { public static void main(String args[]){ int temp, size; int array[] = {10, 20, 25, 63, 96, 57}; size = array.length; for(int i = 0; i
11K+ Views
To find the largest element of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the 1st element from the end of the array.ExampleLive Demopublic class ThirdLargestNumberInAnArray { public static void main(String args[]){ int temp, size; int array[] = {10, 20, 25, 63, 96, 57}; size = array.length; for(int i = 0; i
49K+ Views
To find the second largest element of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the second element from the end of the array.ExampleLive Demopublic class ThirdLargestNumberInAnArray { public static void main(String args[]){ int temp, size; int array[] = {10, 20, 25, 63, 96, 57}; size = array.length; for(int i = 0; i
9K+ Views
To find the third largest number of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the third element from the end of the array.ExampleLive Demopublic class ThirdLargestNumberInAnArray { public static void main(String args[]){ int temp, size; int array[] = {10, 20, 25, 63, 96, 57}; size = array.length; for(int i = 0; i
5K+ Views
Linear search is a very simple search algorithm. In this type of search, a sequential search is done for all items one by one. Every item is checked and if a match is found then that particular item is returned, otherwise the search continues till the end of the data collection.Algorithm1.Get the length of the array. 2.Get the element to be searched store it in a variable named value. 3.Compare each element of the array with the variable value. 4.In case of a match print a message saying element found. 5.else, print a message saying element not foundExampleLive Demopublic class ... Read More
699 Views
Bubble sort is a simple sorting algorithm. This sorting algorithm is a comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order. This algorithm is not suitable for large datasets as its average and worst case complexity is of Ο(n2) where n is the number of items.ExampleLive Demopublic class BubbleSort { static void bubbleSort(int[] arr) { int n = arr.length; int temp = 0; for(int i = 0; i < n; i++) { ... Read More