INDIVIDUAL ASSIGNMENT2026

Practice
sessions.

Java practice solutions, carefully organized with clear explanations and examples.

Explore the solution
SEQUENCE / 01
an = a1 + (n − 1)d
W4JAVA / 01
COURSEProgramming Fundamentals TOPICArithmetic Sequence

01 — AVAILABLE SOLUTION

Practice W4

The program reads a starting value, a step, and a sequence length, then prints an arithmetic sequence.

JGeometricSequencee.java
JAVA
package W4;
import java.util.Scanner;

public class GeometricSequencee {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int n = scanner.nextInt();

        if ((n < 1) || (n > 50)) {
            System.out.println("n must be between 1 and 50");
            return;
        }

        for (int i = 0; i < n; i++) {
            if (i > 0) {
                System.out.print(" ");
            }
            System.out.print(a + i * b);
        }
        System.out.println();
    }
}
01 / 01Available W4 Java solution

This W4 solution is the only practice exercise included in the provided project files.

02 — HOW IT WORKS

From input
to output.

a is the first value, b is the step, and n is the number of values.

01

Read the values

The program reads three integers from standard input: a, b, and n.

02

Validate the length

The sequence length must be from 1 to 50 inclusive. If n is outside that range, the program prints a message and exits.

03

Build the sequence

The loop runs n times. At each step, it calculates a + i * b and separates the values with spaces.

VALUE FORMULAai = a + i × bi starts at 0