Skip to content

Instantly share code, notes, and snippets.

@tauty
Last active December 14, 2015 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tauty/90f3039847ccb1f104de to your computer and use it in GitHub Desktop.
Save tauty/90f3039847ccb1f104de to your computer and use it in GitHub Desktop.
Perl to Java sample code
#
# perl part start
#
use strict;
use warnings;
use IPC::Open2;
my $cmd = "java InteractiveSample";
# コマンドを入出力モードで起動する
my $pid = open2(*READ, *WRITE, $cmd);
my @number = (1 .. 100);
foreach ( @number ) {
# コマンドの標準入力にデータを送る
print WRITE "$_\n";
# コマンドの標準出力からデータを読み出す
my $s = <READ>;
print "$_ -> $s";
}
close(WRITE);
close(READ);
#
# perl part end
#
/**
* Java part start
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class InteractiveSample {
public static void main(String[] args) throws IOException {
int sum = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (String line; null != (line = reader.readLine()); ) {
sum += Integer.parseInt(line);
System.out.println(sum);
}
}
}
/**
* Java part end
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment