**Main.java** import java.io.*; import java.util.Scanner; public class Main { public static void main(String[] args) { try { Scanner scanner = new Scanner(System.in); // Get airport details from the user System.out.println("Enter the name of the airport:"); String name = scanner.nextLine(); System.out.println("Enter the city name:"); String cityName = scanner.nextLine(); System.out.println("Enter the country code:"); String countryCode = scanner.nextLine(); // Write airport details to a CSV file FileWriter writer = new FileWriter("airport.csv"); writer.write(name + "," + cityName + "," + countryCode); writer.close(); System.out.println("Airport details have been written to airport.csv successfully."); } catch (IOException e) { System.out.println("An error occurred while writing to the file."); e.printStackTrace(); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter