This project demonstrates Java's ability to declare and initialize multiple variables of the same type in a single statement. While this approach increases compactness, it is explored here primarily for syntax understanding.
As per the assignment instructions:
- Declare three
intvariables:firstRoll,secondRoll, andtotalScore. - Perform declaration and assignment in one single line.
- Values:
firstRoll= 7secondRoll= 3totalScore= sum of the two.
- Output
totalScoreto the console.
- Language: Java 23
- IDE: IntelliJ IDEA
- Concepts: Compact variable declaration, Arithmetic operations.
The code follows Java naming conventions. Note that while single-line declaration is used here to meet task requirements, Clean Code principles generally recommend declaring each variable on a separate line for better readability.
The code demonstrates how Java handles multiple initializations and arithmetic within a single statement:
package com.yurii.pavlenko;
public class Task_9_App {
public static void main(String[] args) {
// Single-line declaration and initialization
int firstRoll = 7, secondRoll = 3, totalScore = firstRoll + secondRoll;
System.out.println("Total Score: " + totalScore);
}
}In professional development, it is recommended to declare each variable on a new line. Single-line declarations (like in this task) can reduce code readability and make version control (Git) diffs harder to analyze.
This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT