From f9c51538df6d7f18d6b281dd8de519f7493f23c1 Mon Sep 17 00:00:00 2001 From: Ashpreetwadhwa <102176527+Ashpreetwadhwa@users.noreply.github.com> Date: Mon, 10 Oct 2022 00:26:37 +0530 Subject: [PATCH 1/5] Create Sum_of_Array.java --- Array/Sum_of_Array.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Array/Sum_of_Array.java 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()); + } +} From 7fcae222ec5bcc940a1f8f0a90eec18f1d008583 Mon Sep 17 00:00:00 2001 From: Mr Lucky <115186825+LuckyChetan@users.noreply.github.com> Date: Mon, 10 Oct 2022 00:47:50 +0530 Subject: [PATCH 2/5] Created Array --- Array.java | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Array.java 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. From 08009ff4eb6115b29fac02eb540546101ec58444 Mon Sep 17 00:00:00 2001 From: Mr Lucky <115186825+LuckyChetan@users.noreply.github.com> Date: Mon, 10 Oct 2022 00:50:07 +0530 Subject: [PATCH 3/5] Created Multithreading --- Multithreading.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Multithreading.java diff --git a/Multithreading.java b/Multithreading.java new file mode 100644 index 0000000..26d5d68 --- /dev/null +++ b/Multithreading.java @@ -0,0 +1,28 @@ +class MultithreadingDemo extends Thread { + public void run() + { + try { + // Displaying the thread that is running + System.out.println( + "Thread " + Thread.currentThread().getId() + + " is running"); + } + catch (Exception e) { + // Throwing an exception + System.out.println("Exception is caught"); + } + } +} + +// Main Class +public class Multithread { + public static void main(String[] args) + { + int n = 8; // Number of threads + for (int i = 0; i < n; i++) { + MultithreadingDemo object + = new MultithreadingDemo(); + object.start(); + } + } +} From b0c50f031cc538b4dfa493fffa653a9f4a53bcbf Mon Sep 17 00:00:00 2001 From: Stephen Nadar <90613392+StepJes@users.noreply.github.com> Date: Wed, 19 Oct 2022 11:55:21 +0530 Subject: [PATCH 4/5] JAVA-NEW-ReadAndPrint.java --- ReadAndPrint.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 ReadAndPrint.java diff --git a/ReadAndPrint.java b/ReadAndPrint.java new file mode 100644 index 0000000..78cc639 --- /dev/null +++ b/ReadAndPrint.java @@ -0,0 +1,53 @@ +// Java program to take an integer + +// as input and print it + + + +import java.io.*; + +import java.util.Scanner; + + + +class GFG { + + public static void main(String[] args) + + { + + + + // Declare the variables + + int num; + + + + // Input the integer + + System.out.println("Enter the integer: "); + + + + // Create Scanner object + + Scanner s = new Scanner(System.in); + + + + // Read the next integer from the screen + + num = s.nextInt(); + + + + // Display the integer + + System.out.println("Entered integer is: " + + + num); + + } + +} From e93c7a71953a644fd532191d0692ad9b4ff4502c Mon Sep 17 00:00:00 2001 From: Stephen Nadar <90613392+StepJes@users.noreply.github.com> Date: Wed, 27 Sep 2023 00:37:35 +0530 Subject: [PATCH 5/5] Create FibonacciSeries.java --- FibonacciSeries.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 FibonacciSeries.java 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