diff --git a/Beginner/Fibonacci.java b/Beginner/Fibonacci.java new file mode 100644 index 0000000..8e2fccc --- /dev/null +++ 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/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."); + } + } +} 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); + } +} 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."); + } + } +} 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!