├── Fibonacci series ├── First n prime numbers ├── Interface and inheritence ├── Largest and second largest number of an array ├── Maximum and minimum value in an array ├── Prime numbers: 1 to n ├── Removing duplicate elements of array └── Reversing an array /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) 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 | -------------------------------------------------------------------------------- /Maximum and minimum value in an array: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | int[] a = {1, 2, 5, 6, 8}; 4 | int large = a[0]; 5 | int min =a[0]; 6 | 7 | for (int i = 1; i < a.length; i++) { 8 | if (a[i] > 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 | -------------------------------------------------------------------------------- /Prime numbers: 1 to n: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class HelloWorld { 3 | public static void main(String[] args) { 4 | Scanner s = new Scanner(System.in); 5 | System.out.println("Enter a number:"); 6 | int n=s.nextInt(); 7 | for(int i=2;i<=n;i++){ 8 | int c=0; 9 | for(int j=1;j<=i;j++){ 10 | if(i%j==0){ 11 | c++; 12 | } 13 | } 14 | if(c==2){ 15 | System.out.println(i+" "); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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