newbie: How to know witch operator is an string
From: Johan (johankees*AT*_at_dolfijn*DOT*.nl)
Date: 10/31/03
- Next message: Martijn van Steenbergen: "Re: how can I stop a thread from sleeping?"
- Previous message: Jason Teagle: "Re: Putting Packaged Classes Into A JAR File"
- Next in thread: Jason Teagle: "Re: newbie: How to know witch operator is an string"
- Reply: Jason Teagle: "Re: newbie: How to know witch operator is an string"
- Reply: Roedy Green: "Re: newbie: How to know witch operator is an string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Oct 2003 16:06:55 +0100
Hi,
I'm working on an very simple calculator. It has to simple math. I'm
trying to read an string from the command line and then divide it into
numbers and an operator. With the split method of String I can get the
numbers, but how do I get to know what operator is in the string. (for
example 25+5) I also tried to do this with StringTokenizer, but the same
problem here.
...
String[] result = args[0].split("\\+|\\*|\\-|/");
double a = Double.parseDouble(result[0]);
double b = Double.parseDouble(result[1]);
if (args[0].)
System.out.println(a+b);
...
Does anyone know how to do this?
Thanks in advance,
Johan
- Next message: Martijn van Steenbergen: "Re: how can I stop a thread from sleeping?"
- Previous message: Jason Teagle: "Re: Putting Packaged Classes Into A JAR File"
- Next in thread: Jason Teagle: "Re: newbie: How to know witch operator is an string"
- Reply: Jason Teagle: "Re: newbie: How to know witch operator is an string"
- Reply: Roedy Green: "Re: newbie: How to know witch operator is an string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|