Tech Jargon - Decoded
Відкрити в Telegram
Confused by tech terms? Don’t worry, we’ve got you 🤝 We make things simple, one concept at a time. Learn daily Easy & clear Turn Confusion into clarity. #tech #it #softwareengineer #cs #development
Показати більше2 016
Підписники
-124 години
-57 днів
-4030 день
Архів дописів
Toggle Case of String
public class Main {
public static String toggleCase(String str) {
StringBuilder result = new StringBuilder();
for (char c : str.toCharArray()) {
if (Character.isUpperCase(c)) {
result.append(Character.toLowerCase(c));
} else if (Character.isLowerCase(c)) {
result.append(Character.toUpperCase(c));
} else {
result.append(c);
}
}
return result.toString();
}
public static void main(String[] args) {
String input = "Hello World!";
String toggled = toggleCase(input);
System.out.println("Original: " + input);
System.out.println("Toggled: " + toggled);
}
}Check if Two Strings are Rotation of Each Other
public class StringRotation {
public static boolean areRotations(String str1, String str2) {
if (str1 == null || str2 == null || str1.length() != str2.length()) {
return false;
}
if (str1.length() == 0) {
return true;
}
String temp = str1 + str1;
return temp.contains(str2);
}
public static void main(String[] args) {
String str1 = "ABCD";
String str2 = "CDAB";
if (areRotations(str1, str2))
System.out.println("Strings are rotations of each other");
else
System.out.println("Strings are not rotations of each other");
}
}Find First Non-Repeating Character
import java.util.HashMap;
import java.util.Map;
public class FirstNonRepeatingCharacter {
public static Character findFirstNonRepeating(String str) {
Map<Character, Integer> charCounts = new HashMap<>();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
charCounts.put(c, charCounts.getOrDefault(c, 0) + 1);
}
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (charCounts.get(c) == 1) {
return c;
}
}
return null;
}
public static void main(String[] args) {
String input = "programming";
Character result = findFirstNonRepeating(input);
System.out.println("First non-repeating character: " + result);
}
}Remove Duplicate Characters
import java.util.LinkedHashSet;
import java.util.Set;
public class RemoveDuplicates {
public static String removeDuplicates(String str) {
Set<Character> set = new LinkedHashSet<>();
for (char c : str.toCharArray()) {
set.add(c);
}
StringBuilder sb = new StringBuilder();
for (Character c : set) {
sb.append(c);
}
return sb.toString();
}
public static void main(String[] args) {
String input = "programming";
String result = removeDuplicates(input);
System.out.println("Original string: " + input);
System.out.println("String with duplicates removed: " + result);
}
}Count Vowels, Consonants, Digits, Whitespaces in a String
public class StringCounter {
public static void main(String[] args) {
String str = "Hello World 123! This is a Test String.";
int vowels = 0;
int consonants = 0;
int digits = 0;
int spaces = 0;
str = str.toLowerCase();
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch >= 'a' && ch <= 'z') {
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
vowels++;
} else {
consonants++;
}
} else if (ch >= '0' && ch <= '9') {
digits++;
} else if (ch == ' ') {
spaces++;
}
}
System.out.println("Vowels: " + vowels);
System.out.println("Consonants: " + consonants);
System.out.println("Digits: " + digits);
System.out.println("Whitespaces: " + spaces);
}
}Check Anagram Strings
import java.util.Arrays;
public class AnagramChecker {
public static boolean areAnagrams(String str1, String str2) {
if (str1.length() != str2.length()) {
return false;
}
char[] charArray1 = str1.toCharArray();
char[] charArray2 = str2.toCharArray();
Arrays.sort(charArray1);
Arrays.sort(charArray2);
return Arrays.equals(charArray1, charArray2);
}
public static void main(String[] args) {
String str1 = "listen";
String str2 = "silent";
if (areAnagrams(str1, str2)) {
System.out.println(str1 + " and " + str2 + " are anagrams.");
} else {
System.out.println(str1 + " and " + str2 + " are not anagrams.");
}
}
}Check Palindrome String (Ignore Case)
public class Palindrome {
public static boolean isPalindrome(String str) {
str = str.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
int left = 0;
int right = str.length() - 1;
while (left < right) {
if (str.charAt(left) != str.charAt(right)) {
return false;
}
left++;
right--;
}
return true;
}
public static void main(String[] args) {
String testString1 = "Racecar";
String testString2 = "A man, a plan, a canal: Panama";
String testString3 = "hello";
System.out.println("\"" + testString1 + "\" is a palindrome: " + isPalindrome(testString1));
System.out.println("\"" + testString2 + "\" is a palindrome: " + isPalindrome(testString2));
System.out.println("\"" + testString3 + "\" is a palindrome: " + isPalindrome(testString3));
}
}Reverse a String (Iterative & Recursive)
public class StringReverser {
public static String reverseIterative(String str) {
StringBuilder reversed = new StringBuilder();
for (int i = str.length() - 1; i >= 0; i--) {
reversed.append(str.charAt(i));
}
return reversed.toString();
}
public static String reverseRecursive(String str) {
if (str == null || str.isEmpty()) {
return str;
}
return reverseRecursive(str.substring(1)) + str.charAt(0);
}
public static void main(String[] args) {
String input = "hello";
String reversedIterative = reverseIterative(input);
String reversedRecursive = reverseRecursive(input);
System.out.println("Original string: " + input);
System.out.println("Reversed (Iterative): " + reversedIterative);
System.out.println("Reversed (Recursive): " + reversedRecursive);
}
}Reverse a String (Iterative & Recursive)
public class StringReverser { public static String reverseIterative(String str) { StringBuilder reversed = new StringBuilder(); for (int i = str.length() - 1; i >= 0; i--) { reversed.append(str.charAt(i)); } return reversed.toString(); } public static String reverseRecursive(String str) { if (str.isEmpty()) { return str; } return reverseRecursive(str.substring(1)) + str.charAt(0); } public static void main(String[] args) { String input = "Hello"; System.out.println("Original string: " + input); System.out.println("Reversed (iterative): " + reverseIterative(input)); System.out.println("Reversed (recursive): " + reverseRecursive(input)); }}Count Primes Less than N
public class PrimeCounter {
public static int countPrimes(int n) {
if (n <= 2) {
return 0;
}
boolean[] isPrime = new boolean[n];
for (int i = 2; i < n; i++) {
isPrime[i] = true;
}
for (int i = 2; i * i < n; i++) {
if (!isPrime[i]) continue;
for (int j = i * i; j < n; j += i) {
isPrime[j] = false;
}
}
int count = 0;
for (int i = 2; i < n; i++) {
if (isPrime[i]) count++;
}
return count;
}
public static void main(String[] args) {
int n = 10;
int primeCount = countPrimes(n);
System.out.println("Number of primes less than " + n + " is: " + primeCount);
}
}
Вже доступно! Дослідження Telegram за 2025 — головні інсайти року 
