This repository contains a collection of exercises focused on Java programming, specifically designed to practice loops and conditionals. These exercises will help learners improve their understanding of these fundamental programming concepts in Java.
To get started with these exercises, follow these steps:
-
Clone this repository to your local machine using the following command:
git clone https://github.com/nurulashraf/java-loops-and-conditionals-exercises.git
-
Navigate into the directory:
cd java-loops-and-conditionals-exercises -
Ensure you have Java Development Kit (JDK) installed on your machine. If not, download it from here.
-
To compile and run any of the Java exercises, open your terminal or command prompt in the corresponding exercise folder and use the following commands:
javac ExerciseName.java java ExerciseName
The repository includes various Java exercises that demonstrate loops (for, while, do-while) and conditional statements (if, else, switch). Each exercise is contained within its own Java file. You can edit, compile, and run them independently.
- Navigate to a specific exercise:
cd Exercise1 - Compile and run:
javac Exercise1.java java Exercise1
The following exercises are included:
- Exercise 1: For loop to print numbers from 1 to 10.
- Exercise 2: While loop to find the factorial of a number.
- Exercise 3: Use of if-else to check whether a number is even or odd.
- Exercise 4: Switch case to display a day of the week based on user input.
- Exercise 5: Do-while loop to reverse a number.
Each exercise has comments to guide you through the code and explain the concepts used.
Contributions are welcome! If you would like to contribute to this repository, feel free to fork it, make changes, and submit a pull request. Here are some ways you can help:
- Improve existing exercises or add new ones.
- Provide explanations and comments for better clarity.
- Report any issues you find.
This repository is licensed under the MIT License.