This project demonstrates string concatenation in Java by combining numeric flight data with destination text to create a complete status message.
- Create an
intvariable namedflightfor the flight number. - Create a
Stringvariable namedcityfor the destination. - Combine them using the
+operator or theString.format()method into a single string. - Output the final result to the console.
- Language: Java 23 (Current version)
- IDE: IntelliJ IDEA
- Concepts: String Concatenation (int to String).
This task could be solved via simple concatenation. However, following the principles of Сlean Сode, the String.format() method was used to create a clear flight message template.
- Separation of Concerns: The template
"Flight %d to %s"is separated from the data, making the code easier to maintain. - Explicit Formatting: Using
%d(for integers) and%s(for strings) clearly defines the expected data types. - Readability: It avoids the "spaghetti code" of multiple
+operators and quotes.
Flight 747 to Eilat
package com.yurii.pavlenko;
/**
* Task 17: Flight tracking program.
* Demonstrates advanced string formatting using templates.
*/
public class Task_17_App {
public static void main(String[] args) {
// 1. Create a variable for the flight number (primitive type)
int flight = 747;
// 2. Create a variable for the destination city (object type)
String city = "Eilat";
// 3. Format the message using String.format (Clean Code approach)
// %d is a placeholder for the integer (flight)
// %s is a placeholder for the string (city)
String flightInfo = String.format("Flight %d to %s", flight, city);
// 4. Output the final formatted string to the console
System.out.println(flightInfo);
}
}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