0% found this document useful (0 votes)
3 views9 pages

Warmup Java

The document outlines a daily study schedule for preparing for a TCS coding exam, including warm-up exercises on Java syntax, coding questions, and concept reviews. It provides specific coding problems, such as determining Armstrong numbers and finding the second largest element in an array, along with example solutions in Java. Additionally, it includes a comprehensive list of Java concepts and methods to focus on during the study sessions.

Uploaded by

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

Warmup Java

The document outlines a daily study schedule for preparing for a TCS coding exam, including warm-up exercises on Java syntax, coding questions, and concept reviews. It provides specific coding problems, such as determining Armstrong numbers and finding the second largest element in an array, along with example solutions in Java. Additionally, it includes a comprehensive list of Java concepts and methods to focus on during the study sessions.

Uploaded by

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

7:00 PM – 10:00 PM (Every Day Until the Exam)

7:00 – 7:20 (20 min)

Java syntax warm-up

 Arrays
 Strings
 Loops
 Methods
 Scanner
 StringBuilder

No notes. Just refresh your memory.

7:20 – 8:20 (1 hour)

2 Actual TCS Coding Questions (Java)

Cover these topics in rotation:

 Working with Numbers


 Arrays
 Strings
 Patterns
 Matrices
 Number Series
 ASCII

These are the topics most frequently seen in the basic coding round.

8:20 – 9:00 (40 min)

If today's coding question uses a concept you don't know (for example matrices or number
conversion), spend this time learning only that concept.

Don't study an entire chapter. Learn only what today's problems required.

9:00 – 10:00 (1 hour)

One more TCS Coding Question + Review

Read your solution again.


Think:
 Can I simplify it?
 Can I reduce loops?
 Did I miss edge cases?

Instead, I'll say:

Java Coding Warm-up (TCS Quick


Revision)
1. Arrays
int[] arr = new int[5];

int[] arr = {10, 20, 30, 40, 50};

[Link]

arr[0]
arr[[Link] - 1]

2. Scanner
Scanner sc = new Scanner([Link]);

int n = [Link]();

double d = [Link]();

String word = [Link]();

String line = [Link]();

⚠️next() → one word


⚠️nextLine() → whole line

3. Strings
String s = "Hello";

[Link]()

[Link](i)

[Link](1)

[Link]()

[Link]()
[Link](str)

[Link](str)

[Link]("lo")

[Link]('e')

[Link]('l','x')

4. Loops
for(int i = 0; i < n; i++)
while(n > 0)
do{

}while(condition);

5. Methods
int sum(int a, int b){
return a + b;
}
void display(){
[Link]("Hello");
}

6. StringBuilder
StringBuilder sb = new StringBuilder();

[Link]("Hello");

[Link](10);

[Link]();

[Link](1,3);

[Link](2,"Java");

[Link]();

Or

StringBuilder sb = new StringBuilder("Hello");

7. Useful Math
[Link](a,b);

[Link](a,b);

[Link](a,b);

[Link](n);

[Link](n);

8. Character / ASCII
(char)65

(int)'A'

[Link](ch)

[Link](ch)

[Link](ch)

[Link](ch)

9. Arrays Utility
[Link](arr);

[Link](arr);

10. Number Tricks


digit = n % 10;

n = n / 10;

reverse = reverse * 10 + digit;

TCS Coding Question 1 — Armstrong


Number
Problem Statement

An Armstrong number is a number that is equal to the sum of the cubes of its digits.

Write a Java program to determine whether a given integer N is an Armstrong number.


If it is an Armstrong number, print:

Armstrong

Otherwise, print:

Not Armstrong

Sample Input 1
153

Sample Output 1
Armstrong

Sample Input 2
125

Sample Output 2
Not Armstrong

import [Link];

class Main{

public static void main(String[] args){

int n;

Scanner sc=new Scanner([Link]);

[Link]("Enter a number:");

n = [Link]();

int original = 0;

original = n;

int result = 0;

while(n>0){

int digit=n%10;

n=n/10;

result = result + (digit * digit * digit);


}

if (result == original){

[Link]("Armstrong");

else{

[Link]("Not Armstrong");

2. Find the second largest element in an array.

import [Link];

class Main{

public static void main(String[] args);

int n;

Scanner sc=new Scanner([Link]);

[Link]("Enter the size of the array");

n=[Link]();

if (n < 2) {

[Link]("Array must contain at least two elements.");

return;

int[] arr = new int[n];

[Link]("Enter the elements of the array:");

for(int i = 0; i < n; i++){

arr[i] = [Link]();

int max=Integer.MIN_VALUE; //arr[0];


int secondMax=Integer.MIN_VALUE; //arr[0];

for(int i=0;i<[Link];i++){

if(arr[i]>max){

secondMax=max;

max=arr[i];

else if((arr[i]>secondMax) && arr[i]!=max){

secondMax=arr[i];

if (secondMax == Integer.MIN_VALUE) {

[Link]("There is no distinct second largest element.");

} else {

[Link]("The Second largest Element is: " +


secondMax);

}}

Question 3: Reverse a Number


Problem:

Write a Java program to reverse a given number.

Example 1

Input

12345

Output

54321

Example 2
Input

1200

Output

21

Hint (don't scroll further if you want to solve it yourself)

Remember the digit extraction pattern from the Armstrong problem:

digit = n % 10;
n = n / 10;

Now think:

👉 How will you build the reversed number?

If you've already got reverse = 12 and the next digit is 3, what operation should you
perform to make it 123?

import [Link];

class Main{

public static void main(String[] args){

int n;

Scanner sc=new Scanner([Link]);

[Link]("enter the input number");

n=[Link]();

int reverse=0;

while(n>0){

int digit=n%10;

reverse=reverse*10+digit;

n=n/10;
}

[Link](reverse);

You might also like