diff --git a/Array.java b/Array.java new file mode 100644 index 0000000..36bcc9e --- /dev/null +++ b/Array.java @@ -0,0 +1,57 @@ +/*package whatever //do not write package name here */ + +import java.io.*; + +class GFG { + + +// Fuction to rotate array +static void Rotate(int arr[], int d, int n) +{ + // Storing rotated version of array + int temp[] = new int[n]; + + // Keepig track of the current index + // of temp[] + int k = 0; + + // Storing the n - d elements of + // array arr[] to the front of temp[] + for (int i = d; i < n; i++) { + temp[k] = arr[i]; + k++; + } + + // Storing the first d elements of array arr[] + // into temp + for (int i = 0; i < d; i++) { + temp[k] = arr[i]; + k++; + } + + // Copying the elements of temp[] in arr[] + // to get the final rotated array + for (int i = 0; i < n; i++) { + arr[i] = temp[i]; + } +} + +// Function to print elements of array +static void PrintTheArray(int arr[], int n) +{ + for (int i = 0; i < n; i++) { + System.out.print(arr[i]+" "); + } +} + public static void main (String[] args) { + int arr[] = { 1, 2, 3, 4, 5, 6, 7 }; + int N = arr.length; + int d = 2; + + // Function calling + Rotate(arr, d, N); + PrintTheArray(arr, N); + } +} + +// This code is contributed by ishankhandelwals. diff --git a/Array/Sum_of_Array.java b/Array/Sum_of_Array.java new file mode 100644 index 0000000..f034801 --- /dev/null +++ b/Array/Sum_of_Array.java @@ -0,0 +1,24 @@ +// Java Program to find sum of elements in a given array +class Test { + static int arr[] = { 12, 3, 4, 15 }; + + // method for sum of elements in an array + static int sum() + { + int sum = 0; // initialize sum + int i; + + // Iterate through all elements and add them to sum + for (i = 0; i < arr.length; i++) + sum += arr[i]; + + return sum; + } + + // Driver method + public static void main(String[] args) + { + System.out.println("Sum of given array is " + + sum()); + } +} diff --git a/FibonacciSeries.java b/FibonacciSeries.java new file mode 100644 index 0000000..7326348 --- /dev/null +++ b/FibonacciSeries.java @@ -0,0 +1,15 @@ +class FibonacciExample1{ +public static void main(String args[]) +{ + int n1=0,n2=1,n3,i,count=10; + System.out.print(n1+" "+n2);//printing 0 and 1 + + for(i=2;i