Ad
Code
Diff
  • import java.io.*;
    import java.lang.*;
    import java.util.*;
    
    class code {
    	public void print_coding()
    	{
    		System.out.println("Coding");
    	}
    }
    
    class rocks extends code {
    	public void print_rocks() { System.out.println("Rocks!"); }
    }
    
    public class Main {
    	public static void main(String[] args)
    	{
    		rocks t = new rocks();
    		t.print_coding();
    		t.print_rocks();
    	}
    }
    • // Write a project that demonstrates inheritance in C#
    • import java.io.*;
    • import java.lang.*;
    • import java.util.*;
    • class code {
    • public void print_coding()
    • {
    • System.out.println("Coding");
    • }
    • }
    • class rocks extends code {
    • public void print_rocks() { System.out.println("Rocks!"); }
    • }
    • public class Main {
    • public static void main(String[] args)
    • {
    • rocks t = new rocks();
    • t.print_coding();
    • t.print_rocks();
    • }
    • }
Code
Diff
  • import static java.util.stream.DoubleStream.of;
    import static org.apache.commons.lang3.ArrayUtils.reverse;
    
    public class Arraythatdeletesduplicatenumbers {
      
        public static int removeduplicates(int a[], int n)
        {
            if (n == 0 || n == 1) {
                return n;
            }
      
            // creating another array for only storing
            int[] temp = new int[n];
            int j = 0;
      
            for (int i = 0; i < n - 1; i++) {
                if (a[i] != a[i + 1]) {
                    temp[j++] = a[i];
                }
            }
      
            temp[j++] = a[n - 1];
      
            // Changing the original array
            for (int i = 0; i < j; i++) {
                a[i] = temp[i];
            }
      
            return j;
        }
        public static void main(String[] args)
        {
            int a[] = { 1, 1, 2, 2, 2, 10, 10, 30, 30};
            int n = a.length;
      
            n = removeduplicates(a, n);
      
            // Printing The array elements
            for (int i = 0; i < n; i++)
                System.out.print(a[i] + " ");
        }
    }
    
    • import static java.util.stream.DoubleStream.of;
    • import static org.apache.commons.lang3.ArrayUtils.reverse;
    • interface DeleteDuplicates {
    • static double[] deleteDups(double[] a) {
    • // Given an array, eliminate duplicate values and return the array
    • return a;
    • }
    • }
    • public class Arraythatdeletesduplicatenumbers {
    • public static int removeduplicates(int a[], int n)
    • {
    • if (n == 0 || n == 1) {
    • return n;
    • }
    • // creating another array for only storing
    • int[] temp = new int[n];
    • int j = 0;
    • for (int i = 0; i < n - 1; i++) {
    • if (a[i] != a[i + 1]) {
    • temp[j++] = a[i];
    • }
    • }
    • temp[j++] = a[n - 1];
    • // Changing the original array
    • for (int i = 0; i < j; i++) {
    • a[i] = temp[i];
    • }
    • return j;
    • }
    • public static void main(String[] args)
    • {
    • int a[] = { 1, 1, 2, 2, 2, 10, 10, 30, 30};
    • int n = a.length;
    • n = removeduplicates(a, n);
    • // Printing The array elements
    • for (int i = 0; i < n; i++)
    • System.out.print(a[i] + " ");
    • }
    • }