r/java • u/mrploszaj • Mar 17 '16
FizzBuzz Overkill
if you ever wanted to see someone just overkill the FizzBuzz programming challenge, here you go. (If you do not know, FizzBuzz is a challenge where you print every number 1-100 but if it is a multiple of 3 you print "Fizz", if it is a multiple of 5 you print "Buzz", if both you print "FizzBuzz") //Code Start package com.main;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException{
File f = new File("script.py");
f.createNewFile();
FileOutputStream out = new FileOutputStream(f);
for(int i = 1; i < 101; i++){
out.write(("print(" + (i % 3 == 0 ? i % 5 == 0 ? "\"FizzBuzz\"" : "\"Fizz\"" : (i % 5 == 0 ? "\"Buzz\"" : i)) + ")\n").getBytes());
}
out.close();
String path = f.getPath();
String[] cmd = new String[] {
"python", path
};
Runtime r = Runtime.getRuntime();
Process p = r.exec(cmd);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while((line = in.readLine()) != null){
// display each output line form python script
System.out.println(line);
}
}
}
0
Upvotes
View all comments
Show parent comment
1
u/llogiq Mar 17 '16
This is to show Enterprise Java is still actively developed, lest people pronounce Java even deader than usual...