Skip to content

Latest commit

 

History

History
66 lines (44 loc) · 3.33 KB

README.md

File metadata and controls

66 lines (44 loc) · 3.33 KB

Java Fundamentals

Consolidated collection: Java, SQL, and Python exercises are now organized in Programming Exercises. This repository preserves its earlier source and history.

A growing collection of small Java exercises from my programming studies. The exercises are grouped by topic and run independently.

Focus: loops, conditions, console input, and numeric conversion. Class and variable names are in English; simple German comments explain the code.

Exercises

Topic Exercise What it does
Loops NumberSequence Prints the integers from 1 to a user-provided upper limit.
Loops DescendingRange Reads two bounds and prints their inclusive range in descending order.
Loops CandyPurchase Simulates up to ten candy purchases with a price that increases by 10 cents each iteration.
Conversion DecimalToBinary Converts a positive integer into a binary string using remainder and integer division.

Requirements

A Java JDK with javac. No external libraries, Maven, or Gradle are required. The consolidated sources were compiled and checked with JDK 17.

Compile and run

From the repository root, compile all four exercises:

javac -encoding UTF-8 -d out src/fundamentals/loops/NumberSequence.java src/fundamentals/loops/DescendingRange.java src/fundamentals/loops/CandyPurchase.java src/fundamentals/conversion/DecimalToBinary.java

Then run the exercise you want:

java -cp out fundamentals.loops.NumberSequence
java -cp out fundamentals.loops.DescendingRange
java -cp out fundamentals.loops.CandyPurchase
java -cp out fundamentals.conversion.DecimalToBinary

Eclipse users can import the project from the repository root. Other Java IDEs can use src as the source folder.

Examples

Exercise Input Result
NumberSequence 5 1 2 3 4 5
DescendingRange 2, then 5 5, 4, 3, 2 on separate lines
CandyPurchase 100 cents 4 candies and 0 cents remaining
DecimalToBinary 13 1101

Existing behavior and limitations

  • NumberSequence prints numbers rather than calculating their sum. An upper limit below 1 prints no numbers.
  • CandyPurchase checks the money against the previous price before increasing it. Some inputs therefore produce a negative remainder; 0 buys one candy and leaves -10 cents.
  • DecimalToBinary prints an empty result for zero and negative values.
  • The programs expect integer input; nonnumeric input is not handled.

This consolidation changes project structure and package names while preserving the existing calculations and output.

Origins

The exercises were brought together from these earlier repositories:

The earlier if-switch repository had no Java source files at the time of consolidation.