Skip to content
Merged

Raza #217

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/test/java/March/DuplicateWordFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package March;

import java.util.HashSet;
import java.util.Set;

public class DuplicateWordFinder {
public static void main(String[] args) {
String str = "masum raza delhi patna bihar delhi amnour delhi patn";
String words[] = str.split(" ");
Set<String> uniq = new HashSet<String>();
for (String word : words) {
uniq.add(word.trim());
}
for (String word : uniq) {
System.out.println(word);
}
}
}
19 changes: 19 additions & 0 deletions src/test/java/March/EvenLetterPrintFromString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package March;

public class EvenLetterPrintFromString {
public static void main(String[] args) {
String str = "masumrazadelhi";

// Remove spaces completely
str = str.replace(" ", "");

// Now count only characters
for (int i = 0; i < str.length(); i++) {
if (i % 2 == 0) { // even position among letters
System.out.print(str.charAt(i) + " ");
}
}
}
}

//m s m a a e h
17 changes: 17 additions & 0 deletions src/test/java/March/SumOfNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package March;

public class SumOfNumber {
public static void main(String[] args) {
int num = 00;
while (num >= 10) {
int sum = 0;
while (num > 0) {
sum += num % 10;
num = num / 10;
}
num = sum;
}
System.out.println(num);
}

}
50 changes: 50 additions & 0 deletions src/test/java/codeWithLogicExplanation/FindTheDuplicateNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package codeWithLogicExplanation;

import java.util.HashSet;
import java.util.Set;

public class FindTheDuplicateNumber {

public static void main(String[] args) {

// Integer array with some duplicate values (747 appears multiple times)
int ar[] = { 133, 2, 134, 53554, 747, 747, 43634, 747, 86, 346 };

// Input string converted to lowercase for uniform comparison
String input = "India Delhi".toLowerCase();

// Set to store duplicate numbers
Set<Integer> duplicate = new HashSet<>();

// Set to store unique numbers
Set<Integer> uniq = new HashSet<>();

// Loop through each number in the array
for (int num : ar) {
// If adding to uniq fails (already exists), add to duplicate
if (!uniq.add(num)) {
duplicate.add(num);
}
}

// Print duplicate numbers
System.out.println("duplicate number is : " + duplicate);

// Set to store unique characters
Set<Character> uniqs = new HashSet<>();

// Set to store duplicate characters
Set<Character> duplicates = new HashSet<>();

// Loop through each character in the string
for (char c : input.toCharArray()) {
// If adding to uniqs fails (already exists), add to duplicates
if (!uniqs.add(c)) {
duplicates.add(c);
}
}

// Print duplicate characters
System.out.println("duplicate charater is : " + duplicates);
}
}
30 changes: 30 additions & 0 deletions src/test/java/codeWithLogicExplanation/NonRepeatingCharacter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package codeWithLogicExplanation;

public class NonRepeatingCharacter {

public static void main(String arg[]) {

// Input string
String input = "masum raza delhi bihar";
System.out.print("non repeating character is : ");
// Loop through each character
for (char c : input.toCharArray()) {
// If first and last occurrence of the character are the same,
// it means the character appears only once in the string
if (input.indexOf(c) == (input.lastIndexOf(c))) {
System.out.print(c + " ");
}
}
// Another string to check repeating characters
String sc = "bittumasum";
System.out.print("\nrepeating character is: ");
// Loop through each character
for (char d : sc.toCharArray()) {
// If first and last occurrence are different,
// it means the character appears more than once
if (sc.indexOf(d) != (sc.lastIndexOf(d))) {
System.out.print(d + " ");
}
}
}
}
24 changes: 24 additions & 0 deletions src/test/java/codeWithLogicExplanation/PalindromNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package codeWithLogicExplanation;

public class PalindromNumber {

public static void main(String[] args) {

int num = 12321; // The number to check
int rev = 0; // Variable to store the reversed number
int original = num; // Keep a copy of the original number

// Reverse the number
while (num != 0) {
rev = rev * 10 + num % 10; // Take last digit and build reversed number
num = num / 10; // Remove last digit from num
}

// Compare original with reversed
if (original == rev) {
System.out.println(original + " number is palindrome");
} else {
System.out.println(rev + " num is not palindrome");
}
}
}
19 changes: 19 additions & 0 deletions src/test/java/codeWithLogicExplanation/ReversString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package codeWithLogicExplanation;

public class ReversString {

public static void main(String[] args) {

String input = "delhi"; // The original string
String rev = ""; // Variable to store the reversed string
int len = input.length(); // Get the length of the string (5 for "delhi")

// Loop backwards from last character to first
for (int i = len - 1; i >= 0; i--) {
rev = rev + input.charAt(i); // Append each character to rev
}

// Print the reversed string
System.out.println("reverse string is : " + rev);
}
}
24 changes: 24 additions & 0 deletions src/test/java/codeWithLogicExplanation/SumOfNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package codeWithLogicExplanation; // Declares the package name (March). Helps organize classes.

public class SumOfNumber { // Defines the class SumOfNumber
public static void main(String[] args) { // Main method: program entry point
int num = 9876; // Initialize the number you want to process (example: 9876)

// Outer loop: keep running until num becomes a single digit (<= 9)
while (num > 9) {
int sum = 0; // Reset sum for this iteration

// Inner loop: calculate sum of digits of num
while (num > 0) {
sum += num % 10; // Add last digit to sum
num = num / 10; // Remove last digit from num
}

// After summing digits, assign sum back to num
num = sum;
}

// Print the final single-digit result
System.out.println(num);
}
}
29 changes: 29 additions & 0 deletions src/test/java/codeWithLogicExplanation/UpperCaseCountInString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package codeWithLogicExplanation;

public class UpperCaseCountInString {

public static void main(String[] args) {

// Input string to check
String input = "MaDhUBani";

// Counter to keep track of uppercase letters
int count = 0;

// Loop through each character in the string
for (int i = 0; i <= input.length() - 1; i++) {

// Get the character at position i
char c = input.charAt(i);

// Check if the character is uppercase
if (Character.isUpperCase(c)) {
count++; // Increase count if uppercase
System.out.println("Upper character is : " + c);
}
}

// Print total number of uppercase characters found
System.out.println("Total Upper case is : " + count);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Sat Feb 28 11:30:55 IST 2026
#Sun Mar 01 00:25:16 IST 2026
artifactId=interviewPractice2026
groupId=com.interviewPractice2026
m2e.projectLocation=D\:\\My_Project\\Testing_Project\\interviewPractice2026
Expand Down
Binary file not shown.
Binary file not shown.
Binary file added target/test-classes/March/SumOfNumber.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.