From 82dcd03a4f9166309ef05dda801e149ef55a5f1a Mon Sep 17 00:00:00 2001 From: skepttalk Date: Tue, 7 Oct 2025 22:52:33 +0530 Subject: [PATCH 1/5] Add contributing guidelines --- CONTRIBUTING.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..26c5e2e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,25 @@ +# Contributing to Java-Programs + +Thank you for considering contributing to this repository! Here's how you can help: + +## How to Contribute + +1. **Fork the repository**: Click on the "Fork" button at the top-right corner of this page. +2. **Clone your fork**: `git clone https://github.com/your-username/Java-Programs.git` +3. **Create a new branch**: `git checkout -b feature/your-feature` +4. **Make your changes**: Implement your feature or fix. +5. **Commit your changes**: `git commit -m 'Add feature: your-feature'` +6. **Push to your branch**: `git push origin feature/your-feature` +7. **Open a pull request**: Go to the "Pull Requests" tab and click "New Pull Request". + +## Code Style + +- Follow Java naming conventions. +- Write clear and concise commit messages. +- Ensure your code is properly indented and formatted. + +## Issues + +If you find any bugs or have suggestions, please open an issue before submitting a pull request. + +Happy coding! From 51f6aa86997466e9bf73f4dd278d4ff21d2bab24 Mon Sep 17 00:00:00 2001 From: skepttalk Date: Tue, 7 Oct 2025 23:04:04 +0530 Subject: [PATCH 2/5] Add Palindrome.java program --- Beginner/Palindrome.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Beginner/Palindrome.java diff --git a/Beginner/Palindrome.java b/Beginner/Palindrome.java new file mode 100644 index 0000000..959ea4c --- /dev/null +++ b/Beginner/Palindrome.java @@ -0,0 +1,15 @@ +import java.util.Scanner; + +public class Palindrome { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.print("Enter a string: "); + String str = sc.nextLine(); + String reversed = new StringBuilder(str).reverse().toString(); + if(str.equals(reversed)){ + System.out.println(str + " is a palindrome."); + } else { + System.out.println(str + " is not a palindrome."); + } + } +} From ce677772ad0073b8988dfb1f2cb0a432a8b1d0fe Mon Sep 17 00:00:00 2001 From: skepttalk Date: Tue, 7 Oct 2025 23:07:16 +0530 Subject: [PATCH 3/5] Add Prime-Check Program --- Beginner/Prime | 0 Beginner/prime-checker.java | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Beginner/Prime create mode 100644 Beginner/prime-checker.java diff --git a/Beginner/Prime b/Beginner/Prime new file mode 100644 index 0000000..e69de29 diff --git a/Beginner/prime-checker.java b/Beginner/prime-checker.java new file mode 100644 index 0000000..9035fca --- /dev/null +++ b/Beginner/prime-checker.java @@ -0,0 +1,27 @@ +import java.util.Scanner; + +public class PrimeNumber { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.print("Enter a number: "); + int num = sc.nextInt(); + boolean isPrime = true; + + if(num <= 1) { + isPrime = false; + } else { + for(int i = 2; i <= Math.sqrt(num); i++){ + if(num % i == 0){ + isPrime = false; + break; + } + } + } + + if(isPrime){ + System.out.println(num + " is a prime number."); + } else { + System.out.println(num + " is not a prime number."); + } + } +} From 0220f95e0e434e0e74b9500e9b18f850c6f2df10 Mon Sep 17 00:00:00 2001 From: skepttalk Date: Tue, 7 Oct 2025 23:11:08 +0530 Subject: [PATCH 4/5] Add fibonacii-Check Program --- Beginner/{Prime => Fibonacci.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Beginner/{Prime => Fibonacci.java} (100%) diff --git a/Beginner/Prime b/Beginner/Fibonacci.java similarity index 100% rename from Beginner/Prime rename to Beginner/Fibonacci.java From 9751d60705c0431770efe60c286804683cc2b54e Mon Sep 17 00:00:00 2001 From: skepttalk Date: Tue, 7 Oct 2025 23:15:35 +0530 Subject: [PATCH 5/5] Add simple calculator --- Beginner/Fibonacci.java | 18 ++++++++++++++++++ Beginner/calculator.java | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Beginner/calculator.java diff --git a/Beginner/Fibonacci.java b/Beginner/Fibonacci.java index e69de29..8e2fccc 100644 --- a/Beginner/Fibonacci.java +++ b/Beginner/Fibonacci.java @@ -0,0 +1,18 @@ +import java.util.Scanner; + +public class Fibonacci { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.print("Enter the number of terms: "); + int n = sc.nextInt(); + + int a = 0, b = 1; + System.out.print("Fibonacci Sequence: "); + for(int i = 1; i <= n; i++){ + System.out.print(a + " "); + int next = a + b; + a = b; + b = next; + } + } +} diff --git a/Beginner/calculator.java b/Beginner/calculator.java new file mode 100644 index 0000000..aa4992d --- /dev/null +++ b/Beginner/calculator.java @@ -0,0 +1,36 @@ +import java.util.Scanner; + +public class Calculator { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + System.out.print("Enter first number: "); + double num1 = sc.nextDouble(); + + System.out.print("Enter second number: "); + double num2 = sc.nextDouble(); + + System.out.print("Choose operation (+, -, *, /): "); + char op = sc.next().charAt(0); + + double result; + + switch(op){ + case '+': result = num1 + num2; break; + case '-': result = num1 - num2; break; + case '*': result = num1 * num2; break; + case '/': + if(num2 != 0) result = num1 / num2; + else { + System.out.println("Cannot divide by zero."); + return; + } + break; + default: + System.out.println("Invalid operator"); + return; + } + + System.out.println("Result: " + result); + } +}