Spaces:
Sleeping
Sleeping
// YourJavaProgram.java | |
import java.io.FileWriter; | |
import java.io.IOException; | |
public class YourJavaProgram { | |
public static void main(String[] args) { | |
// Check if the input argument is provided | |
if (args.length < 1) { | |
System.out.println("Please provide an input argument."); | |
return; | |
} | |
// Parse the input argument as an integer | |
int number; | |
try { | |
number = Integer.parseInt(args[0]); | |
} catch (NumberFormatException e) { | |
System.out.println("Invalid input argument. Please provide an integer."); | |
return; | |
} | |
// Perform some operation or computation | |
int result = number * 2; | |
// Create a file writer for the output file | |
try (FileWriter writer = new FileWriter("output.txt")) { | |
// Write the result to the output file | |
writer.write(String.valueOf(result)); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |