Ruby vs Java
Blog ยป Ruby vs Java
Posted on 1244240985|%A: %d %B, %Y|agohover
I defend my point! This is the Ruby code
a = gets.to_i b = gets.to_i c = a + b puts c
And this is the corresponding Java code
import java.io.*; public class Addup { static public void main(String args[]) { InputStreamReader stdin = new InputStreamReader(System.in); BufferedReader console = new BufferedReader(stdin); int i1 = 0,i2 = 0; String s1,s2; try { s1 = console.readLine(); i1 = Integer.parseInt(s1); s2 = console.readLine(); i2 = Integer.parseInt(s2); } catch(IOException ioex) { System.out.println("Input error"); System.exit(1); } catch(NumberFormatException nfex) { System.out.println("\"" + nfex.getMessage() + "\" is not numeric"); System.exit(1); } System.out.println(i1 + " + " + i2 + " = " + (i1+i2)); System.exit(0); } } %> javac Addup.java %> java Addup
No more comments.
(Code blocks borrowed from http://www.ariel.com.au/a/teaching-programming.html)
If you like this page, please spread the word:
As well as commenting here, you can tweet or email to me
Add a new comment







