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.Random; | |
| abstract class Compartment | |
| { | |
| public abstract String notice(); | |
| } | |
| class FirstClass extends Compartment | |
| { | |
| @Override |
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
| class Person | |
| { | |
| String name; | |
| public Person(String name) { | |
| this.name = name; | |
| } | |
| public String getName() { | |
| return name; |
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 Test349 { | |
| } | |
| class Node{ | |
| int data; | |
| Node next; | |
| Node(int data){ | |
| this.data=data; |
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.ArrayList; | |
| public class ConsecutiveDuplicates { | |
| public static ArrayList<Integer> duplicates(int arr[]) | |
| { | |
| ArrayList<Integer> obj = new ArrayList<>(); | |
| obj.add(arr[0]); | |
| int count=1; | |
| for (int i = 1; i <arr.length ; i++) { | |
| if(arr[i] != arr[i-1]) | |
| { |
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
| // permutation example | |
| // the input string is "abc" | |
| // print all the permutations of the given string | |
| // ans will be :- | |
| // abc | |
| // acb | |
| // bac | |
| // bca | |
| // cab | |
| // cba |
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 Test90 { | |
| public static void ans(String inp, String ans) | |
| { | |
| // base condition | |
| if(inp.length() ==0 ) | |
| { | |
| System.out.println(ans); | |
| return; |
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
| class Scratch { | |
| // Remove character from the string | |
| // input = "neeraj" | |
| // output= "neerj" | |
| // removing character a from the string | |
| public static String remove(String str) { | |
| // base case | |
| if (str.length() == 0) { | |
| return str; |
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
| class Scratch { | |
| public static void main(String[] args) { | |
| } | |
| } |
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
| //Create an array of 5 elements with values {1,7,4,7,6}.Search value 7 in the given array and print | |
| // all the occurrence(index) of search value(7) by holding the index in a result array . Do it recursively | |
| public class occurrences { | |
| public static int[] sol(int arr[], int ci,int search, int count) | |
| { | |
| // base case | |
| if (ci==arr.length) | |
| { | |
| int [] occarr= new int[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 occurrences { | |
| public static int[] sol(int arr[], int ci,int search, int count) | |
| { | |
| // base case | |
| if (ci==arr.length) | |
| { | |
| int [] occarr= new int[count]; | |
| return occarr; | |
| } | |
| if(arr[ci]== search) |