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) { | |
| 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
| 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) { | |
| 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
| 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 CheckArray { | |
| public static boolean isExists(int[] xr, int[] yr) { | |
| int i = 0; | |
| int j = 0; | |
| while (i < xr.length && j < yr.length) { | |
| if (xr[i] == yr[j]) { | |
| 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
| public class ReversedString { | |
| public static void main(String[] args) { | |
| String input = "GitHub Gist Page"; | |
| // String Covert into an array | |
| char[] stringArray = input.toCharArray(); | |
| for (int i = 0, j = stringArray.length - 1; i < j; i++, j--) { | |
| char temp = stringArray[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
| import java.util.Scanner; | |
| public class TwoDArray { | |
| public static void main(String[] args) { | |
| Scanner input = new Scanner(System.in); | |
| System.out.print("Input number of students: "); | |
| int student = input.nextInt(); |
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 MergeTwoArray { | |
| public static int[] mergeTwoArrays(int[] xr, int[] yr) { | |
| int[] newArray = new int[xr.length + yr.length]; | |
| for (int i = 0; i < xr.length; i++) { | |
| newArray[i] = xr[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
| import java.util.Arrays; | |
| public class ArraySort { | |
| public static void sort(int[] xr) { | |
| for (int i = xr.length - 1; i > 0; i--) { | |
| for (int j = 0; j < i; j++) { |