This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Q1 | |
| CMJD81 :/> notepad Example.java | |
| //----------------------------------------------------------------------- | |
| class Example{ | |
| public static void main(String args[]){ | |
| System.out.println("Hello Java"); | |
| } | |
| } | |
| //----------------------------------------------------------------------- | |
| CMJD81 :/> javac Example.java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| moveToFloor(1); | |
| moveToFloor(2); | |
| moveToFloor(7); | |
| } | |
| private static int currentFloor = 1; | |
| public static void moveToFloor(int destinationFloor) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| public class Compare { | |
| public static void main(String[] args) { | |
| String arrayOne[] = {"Test1", "Test2"}; | |
| String arrayTwo[] = {"Test2", "Test1", "Test3"}; | |
| boolean arrayEquals = false; | |
| if (Arrays.stream(arrayOne).count() == Arrays.stream(arrayTwo).count()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| String input = "GitHub Gist Page"; | |
| char[] stringArray = new char[input.length()]; | |
| for (int i = 0; i < stringArray.length; i++) { | |
| stringArray[i] = input.charAt(i); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 | |
| public class Main { | |
| public static void main(String[] args) { | |
| int n = 15; // You can change this to the number of Fibonacci numbers you want | |
| int first = 0; | |
| int second = 1; | |
| System.out.print(first + ", " + second); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| int input = -121; | |
| System.out.println("Is palindrome " + isPalindrome(input)); | |
| } | |
| public static boolean isPalindrome(int num) { | |
| if (num < 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| String input = "RMR"; | |
| System.out.println("Is palindrome " + isPalindrome(input)); | |
| } | |
| public static boolean isPalindrome(String input) { | |
| String reverseStr = ""; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.HashMap; | |
| import java.util.Map; | |
| public class Main { | |
| public static void main(String[] args) { | |
| // Test cases | |
| System.out.println(romanToInt("III")); // Output: 3 | |
| System.out.println(romanToInt("LVIII")); // Output: 58 | |
| System.out.println(romanToInt("MCMXCIV")); // Output: 1994 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. | |
| Given a string s, return true if it is a palindrome, or false otherwise. | |
| Example 1: | |
| Input: s = "A man, a plan, a canal: Panama" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given a string, determine if a permutation of the string could form a palindrome. | |
| Example 1: | |
| Input: "code" | |
| Output: false | |
| Example 2: | |
| Input: "aab" |