java_assignmnet
java_assignmnet
SRN – PES1PG23CA059
1. Implement a method to perform basic string compression using the counts of repeated characters. For
example, the string “aabcccccaaa” would become a2b1c5a3.
compressed.append(str.charAt(str.length() - 1)).append(count);
2. Find the NORM of a matrix (Square-root of sum of squares of all elements of a matrix)
return Math.sqrt(sumOfSquares);
}
3. Accept first and last name of the user and convert it to twitter handle format.
import java.util.Scanner;
scanner.close();
}
}
2. Shift all zeros to the end of the array (+ve, -ve, 0’s)
import java.util.Arrays;
shiftZerosToEnd(arr);
System.out.println(Arrays.toString(arr));
}
3. Given a string, find the first character that does not repeat anywhere in the string.
import java.util.LinkedHashMap;
import java.util.Map;
1. Accept a word through command line to simulate the game HANGMAN(10 chances)
import java.util.Scanner;
if (!correctGuess) {
chances--;
System.out.println("Incorrect guess! Remaining chances: " + chances);
} else {
System.out.println("Good guess!");
}
if (hiddenWord.toString().equals(word)) {
System.out.println("Congratulations! You guessed the word: " + word);
return;
}
}
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
import java.util.Arrays;
Arrays.sort(charArray1);
Arrays.sort(charArray2);