Skip to content

YuriiJavaDev/JavaBasics_Task_9

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Single-Line Variable Management (JavaBasics_Task_9)

📌 Description

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.

🚀 Task Requirements

As per the assignment instructions:

  1. Declare three int variables: firstRoll, secondRoll, and totalScore.
  2. Perform declaration and assignment in one single line.
  3. Values:
    • firstRoll = 7
    • secondRoll = 3
    • totalScore = sum of the two.
  4. Output totalScore to the console.

📋 Expected Output

Total Score: 10

🛠 Technical Stack

  • Language: Java 23
  • IDE: IntelliJ IDEA
  • Concepts: Compact variable declaration, Arithmetic operations.

⌨️ Practical Implementation

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.

💻 Code Example

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);
   }
}

⚠️ Clean Code Note

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.

⚖️ License

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

About

Educational project. JavaBasics_Task_9 with an example of a single-line variable declaration and a warning that this violates the clean code convention. 150126_0311

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages