Java Program to Print the kth Element in the Array Last Updated : 10 Jul, 2022 Comments Improve Suggest changes Like Article Like Report We need to print the element at the kth position in the given array. So we start the program by taking input from the user about the size of an array and then all the elements of that array. Now by entering the position k at which you want to print the element from the array, the program will print the element at the k-1 position in the array. Note: The indexes of elements in a Java array always start with 0 and continue to the number 1 below the size of the array. Thus, for an array having 10 elements, the indexes will be from 0 to 9. Examples Input: 5 (size of an array) 1, 2, 3, 4, 5 (array elements) 3 (position k) Output: 3 Input: 5 5, 3, 7, 1, 9 3 Output: 7 Java // Java Program to Print the kth Element in the Array import java.io.*; import java.util.Scanner; class GFG { public static void main(String[] args) { { int n; // scanner object to access user input Scanner s = new Scanner(System.in); System.out.print( "Enter number of elements you want in array:"); // storing input in variable n = s.nextInt(); // create int array int a[] = new int[n]; System.out.println("Enter all the elements:"); // iterating for loop to enter the values in the // array for (int i = 0; i < n; i++) { a[i] = s.nextInt(); } System.out.print( "Enter the k th position at which you want to check number:"); int k = s.nextInt(); System.out.println("Number is :" + a[k - 1]); } } } Output Enter number of elements you want in array: 5 Enter all the elements: 5 3 7 1 9 Enter the k th position at which you want to check number: 3 Number is : 7 Comment More infoAdvertise with us Next Article Java Program to Print the kth Element in the Array R ritikasharma23 Follow Improve Article Tags : Java Java Programs Java-Array-Programs Practice Tags : Java Similar Reads Java Program to Print the Smallest Element in an Array Java provides a data structure, the array, which stores the collection of data of the same type. It is a fixed-size sequential collection of elements of the same type. Example: arr1[] = {2 , -1 , 9 , 10} output : -1 arr2[] = {0, -10, -13, 5} output : -13 We need to find and print the smallest value 3 min read Java Program to Print the Elements of an Array An array is a data structure that stores a collection of like-typed variables in contiguous memory allocation. Once created, the size of an array in Java cannot be changed. It's important to note that arrays in Java function differently than they do in C/C++As you see, the array of size 9 holds elem 6 min read Java Program for k-th missing element in sorted array Given an increasing sequence a[], we need to find the K-th missing contiguous element in the increasing sequence which is not present in the sequence. If no k-th missing element is there output -1. Examples : Input : a[] = {2, 3, 5, 9, 10}; k = 1; Output : 1 Explanation: Missing Element in the incre 5 min read Java Program to Find the K'th largest element in a stream Given an infinite stream of integers, find the k'th largest element at any point of time.Example: Input: stream[] = {10, 20, 11, 70, 50, 40, 100, 5, ...} k = 3 Output: {_, _, 10, 11, 20, 40, 50, 50, ...} Extra space allowed is O(k). Recommended: Please solve it on "PRACTICE" first, before moving on 4 min read Java Program to Find the Mth element of the Array after K left rotations Given non-negative integers K, M, and an array arr[] with N elements find the Mth element of the array after K left rotations. Examples: Input: arr[] = {3, 4, 5, 23}, K = 2, M = 1Output: 5Explanation:Â The array after first left rotation a1[ ] = {4, 5, 23, 3}The array after second left rotation a2[ ] 3 min read Java Program to Find Sum of Array Elements Given an array of integers. Write a Java Program to find the sum of the elements of the array. Examples: Input : arr[] = {1, 2, 3} Output : 6 1 + 2 + 3 = 6 Input : arr[] = {15, 12, 13, 10} Output : 50 15 + 12 + 13 + 10 = 50 An array is a data structure that contains a group of elements. Typically th 3 min read Java Program to Print the Elements of an Array Present on Even Position The task is to print all the elements that are present in even position. Consider an example, we have an array of length 6, and we need to display all the elements that are present in 2,4 and 6 positions i.e; at indices 1, 3, 5. Example: Input: [1,2,3,4,5,6] Output: 2 4 6 Input: [1,2] Output: 2 Appr 2 min read Java Program to Sort the Elements of an Array in Descending Order Here, we will sort the array in descending order to arrange elements from largest to smallest. The simple solution is to use Collections.reverseOrder() method. Another way is sorting in ascending order and reversing.1. Using Collections.reverseOrder()In this example, we will use Collections.reverseO 2 min read Java Program to Find Largest Element in an Array Finding the largest element in an array is a common programming task. There are multiple approaches to solve it. In this article, we will explore four practical approaches one by one to solve this in Java.Example Input/Output:Input: arr = { 1, 2, 3, 4, 5}Output: 5Input: arr = { 10, 3, 5, 7, 2, 12}Ou 4 min read Java Program to Print array after it is right rotated K times Given an Array of size N and a values K, around which we need to right rotate the array. How to quickly print the right rotated array?Examples :Â Â Input: Array[] = {1, 3, 5, 7, 9}, K = 2. Output: 7 9 1 3 5 Explanation: After 1st rotation - {9, 1, 3, 5, 7} After 2nd rotation - {7, 9, 1, 3, 5} Input: 2 min read Like