how to send 2 variable value from bash script into java.class

#!/bin/bash

a=10

b=20

echo $a $b | java addition

done

hi there,

currently i have a simple java coding ( a + b ). and i m trying to connect with bash script but this bash script coudln't Enter 2nd value (b=20) while i running for it. may i know how do i can Enter 2 value into it?

output from terminal

[seng@localhost java_class]$ bash addition.sh

=======================================================================

simulation 1

Num_a= 10

Num_b= 20

Enter your Num_a : 10

Enter your Num_b : Exception in thread"main" java.lang.NumberFormatException

at java.lang.Integer.parseInt(java.lang.String, int,boolean) (/usr/lib/libgcj.so.6.0.0)

at java.lang.Integer.parseInt(java.lang.String) (/usr/lib/libgcj.so.6.0.0)

at filter_god.GOD(java.util.List, java.util.List, java.lang.String, java.lang.String,int) (Unknown Source)

at filter_god.main(java.lang.String[]) (Unknown Source)

at gnu.java.lang.MainThread.call_main() (/usr/lib/libgcj.so.6.0.0)

at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)

=======================================================================

[1317 byte] By [questionKIDa] at [2007-11-26 16:09:58]
# 1

That code will send both numbers on a single line in standard input to the java process. So if the process reads standard input, it will get a single line that has this in it: "10 20".

I'm guessing you're sending that whole line to Integer.parseInt. But a valid number doesn't have a space in the middle.

You should split up the line using String.split. Or use a StringTokenizer. Or a regular expression. Or you can use a java.util.Scanner. Or a java.io.StreamTokenizer. Or maybe some other stuff that has slipped my mind at the moment.

paulcwa at 2007-7-8 22:32:18 > top of Java-index,Java Essentials,New To Java...