0% found this document useful (0 votes)
73 views2 pages

TCS NQT Advanced 50 Plus Java Coding

The document provides a comprehensive list of over 50 Java coding questions categorized into sections such as number-based, array-based, string-based, pattern questions, and basic logic & math. Each section includes various coding challenges along with example Java code solutions for some questions. It emphasizes the importance of practicing these questions for the TCS NQT exam, focusing on logic, clean coding, and avoiding built-in shortcuts.

Uploaded by

rp2033923
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views2 pages

TCS NQT Advanced 50 Plus Java Coding

The document provides a comprehensive list of over 50 Java coding questions categorized into sections such as number-based, array-based, string-based, pattern questions, and basic logic & math. Each section includes various coding challenges along with example Java code solutions for some questions. It emphasizes the importance of practicing these questions for the TCS NQT exam, focusing on logic, clean coding, and avoiding built-in shortcuts.

Uploaded by

rp2033923
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TCS NQT – Advanced 50+ Java Coding Questions

with Solutions

SECTION 1: NUMBER BASED QUESTIONS


--------------------------------
1. Palindrome Number
2. Prime Number
3. Prime Numbers in Range
4. Armstrong Number
5. Perfect Number
6. Strong Number
7. Factorial of a Number
8. Fibonacci Series
9. Reverse a Number
10. Sum of Digits
11. GCD of Two Numbers
12. LCM of Two Numbers
13. Count Digits
14. Power of a Number
15. Check Even or Odd

SECTION 2: ARRAY BASED QUESTIONS


--------------------------------
16. Find Largest Element
17. Find Smallest Element
18. Second Largest Element
19. Reverse an Array
20. Sum of Array Elements
21. Count Even and Odd Elements
22. Remove Duplicate Elements
23. Sort Array Ascending
24. Sort Array Descending
25. Find Missing Number
26. Merge Two Arrays
27. Frequency of Elements
28. Left Rotate Array
29. Right Rotate Array
30. Find Common Elements

SECTION 3: STRING BASED QUESTIONS


--------------------------------
31. Reverse a String
32. Palindrome String
33. Count Vowels and Consonants
34. Remove Spaces from String
35. Frequency of Characters
36. Check Anagram
37. Convert Lowercase to Uppercase
38. Find Duplicate Characters
39. Count Words in String
40. Replace Character in String

SECTION 4: PATTERN QUESTIONS


--------------------------------
41. Star Pattern Pyramid
42. Reverse Star Pattern
43. Number Triangle Pattern
44. Floyd’s Triangle
45. Alphabet Pattern

SECTION 5: BASIC LOGIC & MATH


--------------------------------
46. Swap Two Numbers
47. Leap Year Check
48. Maximum of Three Numbers
49. Simple Calculator
50. Check Positive or Negative Number
51. Find ASCII Value
52. Generate Random Number
53. Sum of Natural Numbers
54. Multiplication Table
55. Check Character is Alphabet or Not
SECTION 6: IMPORTANT JAVA PROGRAMS (WITH CODE)
----------------------------------------------

Example: Palindrome Number (Java Code)

import [Link].*;
class Palindrome {
public static void main(String[] args){
Scanner sc=new Scanner([Link]);
int n=[Link](),rev=0,temp=n;
while(n>0){
rev=rev*10+n%10;
n/=10;
}
[Link](temp==rev?"Palindrome":"Not Palindrome");
}
}

Example: Prime Number (Java Code)

import [Link].*;
class Prime {
public static void main(String[] args){
Scanner sc=new Scanner([Link]);
int n=[Link]();
boolean prime=true;
if(n<=1) prime=false;
for(int i=2;i<=n/2;i++){
if(n%i==0){ prime=false; break; }
}
[Link](prime?"Prime":"Not Prime");
}
}

Example: Reverse String (Java Code)

import [Link].*;
class ReverseString {
public static void main(String[] args){
Scanner sc=new Scanner([Link]);
String s=[Link](),rev="";
for(int i=[Link]()-1;i>=0;i--)
rev+=[Link](i);
[Link](rev);
}
}

NOTE:
Practice these questions daily.
TCS NQT focuses on logic, clean code, and correct output.
Avoid using built-in shortcuts in exam.

Best of Luck for TCS NQT!

Common questions

Powered by AI

Creating a number triangle pattern involves using nested loops in Java. The outer loop iterates over the rows, while the inner loop prints numbers in increasing order from 1 up to the current row number. The number of rows and number increments in each row determine the size and shape of the triangle pattern. For example, for a pattern of 5 rows, the first row prints 1, the second prints 1 2, and so forth up to the last row .

Java uses the Random class to generate random numbers. By creating an instance of Random and calling its nextInt or nextDouble methods, pseudo-random numbers within specific ranges can be produced. This is valuable for tasks like simulating random events, initializing unpredictable data for tests, or generating variable outcomes in games or scientific calculations .

A palindrome number can be checked in Java by reversing the original number and comparing it with the original. The process involves extracting the digits of the number in reverse order by repeatedly taking the remainder of division by 10, multiplying the reverse by 10, and adding the remainder. Once reversed, it is compared to the original number to determine if it is a palindrome .

Handling sorted array rotations in Java involves using temporary storage to hold elements during rotations. For left rotation, elements from the beginning of the array are temporarily stored, moved to the end after the remaining elements are shifted to the left. For right rotation, a similar process is applied in reverse. This preserves the order of elements, maintaining a sorted sequence post-rotation .

An anagram checking program in Java is important for comparing two strings to determine if one is a permutation of another. The logic involves sorting both strings and comparing them for equality. Alternatively, a frequency count of each letter can be performed; if both strings have identical frequency counts for all characters, they are anagrams. This approach ensures that the same characters are present in both strings in the same frequency .

The Euclidean algorithm is used to find the GCD of two numbers. In Java, this is implemented by repeatedly replacing the larger number with the remainder of the division of the two numbers (a % b) until the remainder is zero; the non-zero remainder or the last non-zero divisor is the GCD .

Merging two arrays in Java can be efficiently done by iterating through both arrays and sequentially adding elements to a resultant array. This requires keeping track of indices in both input arrays, appending the lesser of the current elements from the arrays, and incrementing the respective index. This approach assumes both arrays are sorted, aiming for linear time complexity, O(n + m), where n and m are the lengths of the two arrays respectively .

To find consecutive prime numbers within a given range in Java, iterate through each number in the range, checking each for primality. For each number, divisibility is checked only up to its square root. If the number has no divisors other than 1 and itself, it is marked as prime. Collecting these results in a list or similar structure will yield the consecutive primes in the range .

To check if a character is an alphabet in Java, compare its ASCII value against the defined ranges for alphabets ('a' to 'z' and 'A' to 'Z'). This is fundamental in scenarios requiring strict input validation or parsing, ensuring the input character is a permissible letter. Such checks are crucial in applications where numerical or special characters are invalid .

To compute the frequency of each character in a string using Java, iterate through the string and use a hash map (or similar data structure) to store characters as keys and their counts as values. For each character in the string, increment its count in the map. This approach handles different character occurrences in the string efficiently .

You might also like