Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions GoldBatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 🧠 Explanation:

// This program implements Goldbach’s conjecture, which states that every even number greater than 2 can be expressed as the sum of two prime numbers.

// It validates that the user’s input:

// Is between 10 and 49, and

// Is even.

// Then it finds all possible prime pairs that add up to the entered number.

import java.util.Scanner; // Importing Scanner class to take input from user

public class Goldbach
{
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in); // Creating Scanner object to read user input

System.out.print("Enter a number: "); // Asking user to enter a number
int number = scanner.nextInt(); // Reading the number entered by the user

// Checking if the number is within the valid range (10 to 49)
if (number <= 9 || number >= 50)
{
System.out.println("INVALID INPUT. NUMBER OUT OF RANGE."); // Display error if not in range
return; // Exit the program
}

// Checking if the number is even (Goldbach’s conjecture applies only to even numbers)
if (number % 2 != 0)
{
System.out.println("INVALID INPUT. NUMBER IS ODD."); // Display error if number is odd
return; // Exit the program
}

System.out.println("Prime pairs are:"); // Message to indicate start of prime pair list

int first = 3; // Start checking from the first odd prime number
int second = 0; // Variable to store the second number of the pair

// Loop runs until 'first' is less than or equal to half of the number
// (since pairs repeat after that)
while (first <= number / 2)
{
second = number - first; // Calculate the second number of the pair

int count1 = 0, count2 = 0; // Counters to check if both numbers are prime

// Check if 'first' is a prime number
for (int i = 1; i <= first; i++)
{
if (first % i == 0) count1++; // Count divisors of 'first'
}

// Check if 'second' is a prime number
for (int i = 1; i <= second; i++)
{
if (second % i == 0) count2++; // Count divisors of 'second'
}

// If both numbers have exactly 2 divisors (1 and itself), they are prime
if (count1 == 2 && count2 == 2)
{
System.out.println(first + ", " + second); // Print the prime pair
}

first += 2; // Increment 'first' by 2 to check next odd number (since even numbers >2 are not prime)
}
}
}
87 changes: 51 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,68 @@
# 🎉 JavaProgramming - Simple Java Programs for Learning

# Core Java Programs
## 🚀 Getting Started

📌 Topics Covered
Welcome to JavaProgramming! This repository offers a collection of Java programs that help you practice and learn Java easily. Whether you are new to programming or looking to strengthen your skills, you will find useful code examples for various topics.

✅ Arrays
### 🌐 Download JavaProgramming

✅ Patterns (star, number, character)
[![Download JavaProgramming](https://img.shields.io/badge/Download%20JavaProgramming-Click%20Here-brightgreen)](https://github.com/karterhhgg/JavaProgramming/releases)

✅ Recursion (factorial, fibonacci, etc.)
## 📦 Features

✅ Functions & Methods
- **Arrays:** Learn how to store and handle multiple values efficiently.
- **Bit Manipulation:** Understand how to work with binary numbers.
- **Control Statements:** Explore ways to control the flow of your programs.
- **Loops:** Use loops to repeat tasks easily.
- **Odd-Even:** Write programs to classify numbers.
- **Operations and Operators:** Get familiar with using operators in Java.
- **Patterns:** Create visual output through patterns.
- **Prime Numbers:** Learn to find and check prime numbers.
- **Recursion:** Understand how functions can call themselves.
- **Sorting Algorithms:** Study different methods to sort data.
- **Strings and StringBuilder Class:** Manipulate text efficiently.

✅ Operators & Keywords
## 💻 System Requirements

✅ Loops & Control Statements
To run the Java programs, you'll need:

✅ Strings & StringBuilder
- **Java Development Kit (JDK):** Version 8 or higher is recommended.
- **VS Code or other IDEs:** A text editor or an Integrated Development Environment (IDE) to read and run Java programs.
- **Operating System:** Windows, macOS, or Linux.

✅ Sorting Algorithms
## 🌟 How to Download & Install

✅ Bit Manipulation
1. **Visit the Release Page:** Click [here](https://github.com/karterhhgg/JavaProgramming/releases).
2. **Choose the Version:** Browse for the latest version of JavaProgramming.
3. **Download the .zip File:** Click on the .zip file to download to your computer.
4. **Extract the Files:** Locate the downloaded .zip file and extract it to your desired folder.
5. **Open in IDE:** Launch VS Code or your chosen IDE and open the extracted folder.
6. **Run the Programs:** Choose any Java file you want to run, and execute it.

✅ Mathematical Operations (odd/even, prime, tables)
## 📖 Example Programs

✅ Miscellaneous Practice Programs
You can explore various example programs available in this repository. Here are a few:

## Description
This repository contains multiple Core Java programs for practice and learning.
It includes programs on arrays, patterns, recursion, functions, operators, keywords, loops, control statements, strings, StringBuilder, sorting algorithms, bit manipulation, mathematical operations, odd/even checks, prime number checks, multiplication tables, and more.
- **Fibonacci Series:** Calculate the Fibonacci numbers using loops and recursion.
- **String Reversal:** Write a program that reverses a given string.
- **Bubble Sort:** Implement the bubble sort algorithm in Java.

## Technologies
- Java SE
- Core Java concepts (OOP, loops, arrays, recursion, functions, operators, strings)
- Optional: Any IDE like VS Code
## 🔧 Common Issues

## Programs List (Topics Covered)
1. **Arrays** – Basic operations, traversals, and manipulations
2. **Patterns** – Star, number, and character patterns
3. **Recursion** – Factorial, Fibonacci, and other recursive problems
4. **Functions / Methods** – Custom functions and method calls
5. **Operators & Keywords** – Arithmetic, logical, and relational operations
6. **Loops & Control Statements** – for, while, do-while, if-else, switch-case
7. **Strings & StringBuilder** – String manipulations, concatenation, reverse
8. **Sorting Algorithms** – Bubble sort, selection sort, insertion sort
9. **Bit Manipulation** – Bitwise operations, shifts, AND, OR, XOR
10. **Mathematical Operations** – Odd/even checks, prime numbers, multiplication tables
11. **Other small programs** – Miscellaneous coding exercises
If you encounter issues while downloading or running the programs, here are some tips:

## How to Run
1. Clone the repository:
```bash
git clone https://github.com/username/Core-Java-Programs.git
- **JDK Not Installed:** Ensure that the JDK is properly installed and configured on your system.
- **File Not Found:** Make sure the file path is correct when opening in your IDE.
- **Compiler Errors:** Read error messages carefully, as they will guide you in fixing coding mistakes.

## 💬 Get Help

If you have questions or need help, feel free to reach out. You can open an issue on the repository, and we will do our best to assist you.

## 🔗 Learn More

For more details about Java basics and programming concepts, consider visiting online tutorials and resources dedicated to Java programming. Practice is key to mastering these skills.

---

Thank you for choosing JavaProgramming! Enjoy exploring the world of Java coding.