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

Tcs Ipa Cheatsheet

The TCS IPA Exam Cheatsheet covers essential programming concepts including custom classes, array of objects, and static methods with examples. It provides input/output templates using BufferedReader, string and character methods, array operations, and common problem patterns. Important notes and common mistakes to avoid are also highlighted to aid in exam preparation.

Uploaded by

Prayas Dash
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)
60 views6 pages

Tcs Ipa Cheatsheet

The TCS IPA Exam Cheatsheet covers essential programming concepts including custom classes, array of objects, and static methods with examples. It provides input/output templates using BufferedReader, string and character methods, array operations, and common problem patterns. Important notes and common mistakes to avoid are also highlighted to aid in exam preparation.

Uploaded by

Prayas Dash
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
You are on page 1/ 6

TCS IPA Exam Cheatsheet

Core Concepts to Master

1. Custom Classes (High Priority)

class Student {
private int id;
private String name;
private double marks;

// Constructor
public Student(int id, String name, double marks) {
this.id = id;
this.name = name;
this.marks = marks;
}

// Getters
public int getId() { return id; }
public String getName() { return name; }
public double getMarks() { return marks; }

// Setters
public void setId(int id) { this.id = id; }
public void setName(String name) { this.name = name; }
public void setMarks(double marks) { this.marks = marks; }
}

2. Array of Objects

Student[] students = new Student[5];


students[0] = new Student(101, "John", 85.5);

3. Static Methods Pattern

public static int findAverage(Student[] students, String searchName) {


int total = 0;
int count = 0;

for (Student s : students) {


if (s.getName().equalsIgnoreCase(searchName)) {

1
total += s.getMarks();
count++;
}
}
return count > 0 ? total/count : 0;
}

Essential Input/Output Templates

BufferedReader (Use This for TCS)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Solution {


public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));

String name = br.readLine(); // Read string


int age = Integer.parseInt(br.readLine()); // Read integer
double salary = Double.parseDouble(br.readLine()); // Read double

// For splitting strings


String[] words = name.split(" "); // "John Doe" → ["John", "Doe"]
}
}

String Methods (Memorize All)

String text = "Hello World";

// Basic Info
text.length() // Returns 11
text.charAt(0) // Returns 'H'

// Case Conversion
text.toLowerCase() // "hello world"
text.toUpperCase() // "HELLO WORLD"

// Splitting and Extracting


text.split(" ") // ["Hello", "World"]
text.substring(0, 5) // "Hello"

2
text.trim() // Removes spaces from start/end

// Searching
text.indexOf('o') // Returns 4 (first position)
text.lastIndexOf('o') // Returns 7 (last position)
text.contains("llo") // Returns true

// Comparison
text.equals("Hello World") // Exact match (case sensitive)
text.equalsIgnoreCase("hello world") // Ignore case

// Checking Start/End
text.startsWith("He") // Returns true
text.endsWith("ld") // Returns true

// Replacement
text.replace('l', 'x') // "Hexxo Worxd"

Character Methods

char letter = 'A';

Character.isDigit(letter) // false (not a number)


Character.isLetter(letter) // true (is a letter)
Character.toLowerCase(letter) // 'a'
Character.toUpperCase(letter) // 'A'

// Check if vowel
char c = 'a';
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
// It's a vowel
}

Array Operations

int[] numbers = new int[5];


numbers.length // Array size

// Import needed for sorting


import java.util.Arrays;
Arrays.sort(numbers); // Sort from small to big

3
Math Methods

Math.max(10, 20) // Returns 20 (bigger number)


Math.min(10, 20) // Returns 10 (smaller number)
Math.abs(-5) // Returns 5 (positive value)

Type Conversion

// String to Numbers
int number = Integer.parseInt("123"); // "123" → 123
double decimal = Double.parseDouble("12.34"); // "12.34" → 12.34

// Numbers to String
String text = String.valueOf(123); // 123 → "123"
String text2 = Integer.toString(456); // 456 → "456"

Common Problem Patterns

1. Count Words Starting with Vowels

String sentence = "Everyone should practice";


String[] words = sentence.split(" ");
int count = 0;

for (String word : words) {


if (word.length() > 0) {
char firstLetter = word.toLowerCase().charAt(0);
if (firstLetter == 'a' || firstLetter == 'e' || firstLetter == 'i' ||
firstLetter == 'o' || firstLetter == 'u') {
count++;
}
}
}

2. Filter Objects by Condition

public static int calculateAverage(Student[] students, String course) {


int totalMarks = 0;
int studentCount = 0;

for (Student student : students) {


if (student.getCourse().equalsIgnoreCase(course) && student.getMarks()

4
> 60) {
totalMarks += student.getMarks();
studentCount++;
}
}

if (studentCount > 0) {
return totalMarks / studentCount;
} else {
return 0;
}
}

3. Find Second Largest Number

int[] numbers = {10, 5, 20, 8, 15};


int largest = Integer.MIN_VALUE;
int secondLargest = Integer.MIN_VALUE;

for (int num : numbers) {


if (num > largest) {
secondLargest = largest;
largest = num;
} else if (num > secondLargest && num != largest) {
secondLargest = num;
}
}

Important Notes
• Always use equalsIgnoreCase() for comparing strings (ignores CAPS/small)

• Handle empty cases: empty strings, no matching results

• Follow exact output format mentioned in problem & Remember to import classes when needed

• Use simple for loops: for (Student s : students) instead of for (int i = 0; i <
length; i++)

• Convert double to int when required: (int)(decimalNumber)

Common Mistakes to Avoid


• Forgetting case sensitivity in string comparison

5
• Using Scanner instead of BufferedReader (TCS systems have issues with Scanner)
• Missing edge cases (empty arrays, no matches found)
• Wrong output format (extra spaces, wrong capitalization)
• Not importing required classes
• Using wrong return types in methods (int vs double)

You might also like