0% found this document useful (0 votes)
113 views6 pages

Java Practice Coding Questions

Uploaded by

Sankit Ingale
0% found this document useful (0 votes)
113 views6 pages

Java Practice Coding Questions

Uploaded by

Sankit Ingale
You are on page 1
6
 
Question 1: Java Coding Question:
Problem
:You are given a String array containing numeric strings. Your task is to reverse the strings at odd indices of the array, and then sum the reversed value with the string at the even index. After summing, if the length of the resulting string is greater than 5, you need to take the first 5 digits and store it in the corresponding index of a new output array.Requirements:1. Input: A String inputArray where each element is a numeric string.2. Processing:• For each string at odd index (1, 3, 5, etc.), reverse the string.For each even index (0, 2, 4, etc.), sum the original string at that index withthe reversed string at the odd index immediately following it.If the resulting sum exceeds 5 digits, take the first 5 digits of the sum.3. Output: The new String[] outputArray which contains the transformed values according to the rule above.Constraints:The input array contains only numeric strings.The array can be of any length, but the length will always be at least 2.
Input
: String inputArray("12345", "67890", "45678", "13579");
Output
: String[] outputArray("22221", "14320");
 
Question 4 : Java Coding Question
Problem
: You are given a String array containing numeric strings. Your task is to multiply the strings at even indices by 2 and reverse the strings at odd indices. Then, concatenate each pair (even index string with the following odd index string) and if the resulting string length is greater than 6, keep only the last 6 digits in the output array.
Requirements
:
1.
Input: A String inputArray where each element is a numeric string.
2.
Processing: • For each string at even index (0, 2, 4, etc.), mulply the numeric value by 2 • For each string at odd index (1, 3, 5, etc.), reverse the string • Concatenate each even-indexed result with its following odd-indexed result • If the concatenated string exceeds 6 digits, take the last 6 digits
3.
Output: A new String[] outputArray containing the transformed values according to the rules above.
Constraints
:
 
The input array contains only numeric strings
 
Each string in the input array will contain between 1 and 5 digits
 
The array length will always be even and at least 2
 
All numbers are posive integers
Example:Input : String [] inputArray = {“123” , “456” , “789” , “321” }Output: String [] outputString = { “246654” , “578123” }

Unlock this document

Upload a document to download this document or subscribe to read and download.

or

Unlock the next 6 pages after an ad

6
 
Question 5 : Java Coding Question
Problem: Given an array of strings, create a chain where each subsequent string is derived from the previous string using these rules:
 
If the previous string ends with a vowel, append its length to the current string
 
If it ends with a consonant, prepend the current string's length to it
 
If it ends with a number, reverse the current string
Input
: String[] arr = {"hello", "world", "code", "java"}Process:"hello" → ends with 'o' (vowel) → "world5""world5" → ends with '5' (number) → "edoc""edoc" → ends with 'c' (consonant) → "4java"
Output
: String[] result = {"hello", "world5", "edoc", "4java"}

Unlock this document

Upload a document to download this document or subscribe to read and download.

or

Unlock the next 6 pages after an ad

6
 
Question 6 : Java Coding Question
Problem:
 Given a list of daily temperatures, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put
0
 instead.
Input:
int[] temperatures = {73, 74, 75, 71, 69, 72, 76, 73};
Output:
int[] result = {1, 1, 4, 2, 1, 1, 0, 0};
 
Question 7 : Java Coding Question
Problem:
 You are given a String array containing numeric strings. Your task is to perform the following operations:1. For strings at even indices (0, 2, 4, etc.), append the length of the string to itself.2. For strings at odd indices (1, 3, 5, etc.), prepend the length of the string to itself. If the resulting string exceeds 5 characters, take the first 5 characters and store them in the corresponding index of a new output array.
Input:
String[] inputArray = {"123", "4567", "890", "12345"};
Output:
String[] outputArray = {"1233", "44567", "8903", "51234"};
Question 8 : Java Coding Question
Problem:
 Given a string and an array of indices, replace the characters of the string at given indices with a specified character.
Input:
String s = "hello";int[] indices = {1, 3};char replacement = '*';
Output:
String result = "h*l*o";
 
Question 9 : Java Coding Question
Problem:
 Given two arrays of strings, interleave them to form a single array. If one array is longer than the other, append the remaining elements of the longer array at the end.
Input:
 java
String[] arr1 = {"a", "b", "c"};String[] arr2 = {"1", "2", "3", "4"};
Output:
String[] result = {"a", "1", "b", "2", "c", "3", "4"};
576648e32a3d8b82ca71961b7a986505