├── Fibonacci series ├── Maximum and minimum value in an array ├── Reversing an array ├── Removing duplicate elements of array ├── Prime numbers: 1 to n ├── Largest and second largest number of an array ├── First n prime numbers └── Interface and inheritence /Fibonacci series: -------------------------------------------------------------------------------- 1 | // Online Java Compiler 2 | // Use this editor to write, compile and run your Java code online 3 | import java.util.Arrays; 4 | class HelloWorld { 5 | public static void main(String[] args) { 6 | int n=500; 7 | int a=0; 8 | int b=1; 9 | int c=0; 10 | while (c large) 9 | { 10 | large = a[i]; 11 | } 12 | else min=a[i]; 13 | } 14 | 15 | System.out.println(large); 16 | System.out.println(min); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Reversing an array: -------------------------------------------------------------------------------- 1 | public class Main 2 | { 3 | public static void main(String[] args){ 4 | int[] a = {9,3,8,6}; 5 | int i=0,j=a.length-1; 6 | while (i < j) 7 | { 8 | int t = a[i]; 9 | a[i] = a[j]; 10 | a[j] = t; 11 | i++; 12 | j--; 13 | } 14 | for (i = 0; i < a.length; i++){ 15 | System.out.println(a[i]); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Removing duplicate elements of array: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | class HelloWorld { 3 | public static void main(String[] args) { 4 | int a[]={8,7,2,9,5,4,3,5,1}; 5 | int b[]=new int[a.length]; 6 | int t=0; 7 | int c = 0; 8 | Arrays.sort(a); 9 | for(int i=0;i large) 8 | { 9 | slarge = large; 10 | large = a[i]; 11 | } 12 | else if (a[i]>slarge){ 13 | if (a[i] == large) continue; 14 | slarge=a[i]; 15 | } 16 | else{ 17 | continue; 18 | } 19 | } 20 | 21 | System.out.println(large+"\n"+slarge); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /First n prime numbers: -------------------------------------------------------------------------------- 1 | package prime; 2 | import java.util.*; 3 | import java.lang.Math; 4 | public class prime { 5 | public static void main(String[]args) 6 | { 7 | final long startTime = System.currentTimeMillis(); 8 | int divisor,n=0,i=2; 9 | Scanner s = new Scanner(System.in); 10 | int x=s.nextInt(); 11 | while(n