Click here to Skip to main content
15,908,626 members
Home / Discussions / Java
   

Java

 
QuestionOracle Driver problem Pin
itsh117-Oct-10 18:36
itsh117-Oct-10 18:36 
AnswerRe: Oracle Driver problem Pin
Richard MacCutchan7-Oct-10 22:30
mveRichard MacCutchan7-Oct-10 22:30 
AnswerRe: Oracle Driver problem Pin
David Skelly8-Oct-10 1:45
David Skelly8-Oct-10 1:45 
Questionhelp in j2me Pin
allaa2507-Oct-10 5:10
allaa2507-Oct-10 5:10 
AnswerRe: help in j2me Pin
Gerben Jongerius7-Oct-10 7:13
Gerben Jongerius7-Oct-10 7:13 
QuestionSimple Java Problem Pin
andyjin77776-Oct-10 17:55
andyjin77776-Oct-10 17:55 
AnswerRe: Simple Java Problem Pin
Cedric Moonen6-Oct-10 20:33
Cedric Moonen6-Oct-10 20:33 
AnswerRe: Simple Java Problem [modified] Pin
SinghUlarity...8-Oct-10 5:54
SinghUlarity...8-Oct-10 5:54 
As explained above, let me make it a bit more clearer for you

import java.util.*;
import java.text.*;
import javax.swing.*;
class Lab4Part2{
public static void main (String[] args) {
String ex1;
double sum, F, a=0, b=0;
JFrame myWindow=new JFrame();
myWindow.setSize(500,400);
myWindow.setTitle("Calculator");
myWindow.setVisible(true);
myWindow.setLocation(600,200);
ex1=JOptionPane.showInputDialog(myWindow, "Enter an expression");
//F=Double.parseDouble(ex1);  You cannot parse the whole string as double since it has 
              //a '+' sign and besides the user might enter other invalid Characters
//Validate that the user entry is in the valid form so check the input to see if there 
      //is anything else besides numbers and + sign in the input, something like this
//"^\\d+[\\+]\\d+$" is a regex to validate the i/p, try researching on your own to figure 
              //out
if(Pattern.compile("^\\d+[\\+]\\d+$").matcher(ex1).find()) {
  String[] inputnums = ex1.split("+");
  a = Double.parseDouble(inputnums[0]);
  b = Double.parseDouble(inputnums[1]);
}
else
 //throw an exception informing the user that the i/p is incorrect.

//sum=(a+B); mind the case
//sum=a+b;
JOptionPane.showMessageDialog(myWindow, "The sum is "+sum);
}
}


--Modified the regex
I are n00b.
modified on Friday, October 8, 2010 12:08 PM

GeneralRe: Simple Java Problem Pin
SinghUlarity...8-Oct-10 6:00
SinghUlarity...8-Oct-10 6:00 
QuestionMessage Removed Pin
5-Oct-10 8:32
vivek8865-Oct-10 8:32 
AnswerRe: JAVA program to check please answer Pin
Dr.Walt Fair, PE5-Oct-10 11:19
professionalDr.Walt Fair, PE5-Oct-10 11:19 
GeneralRe: JAVA program to check please answer Pin
vivek8865-Oct-10 23:02
vivek8865-Oct-10 23:02 
AnswerRe: JAVA program to check please answer Pin
Richard MacCutchan5-Oct-10 11:35
mveRichard MacCutchan5-Oct-10 11:35 
GeneralRe: JAVA program to check please answer Pin
vivek8865-Oct-10 23:02
vivek8865-Oct-10 23:02 
GeneralRe: JAVA program to check please answer Pin
Richard MacCutchan5-Oct-10 23:06
mveRichard MacCutchan5-Oct-10 23:06 
GeneralRe: JAVA program to check please answer Pin
vivek8865-Oct-10 23:32
vivek8865-Oct-10 23:32 
GeneralRe: JAVA program to check please answer Pin
TorstenH.6-Oct-10 0:11
TorstenH.6-Oct-10 0:11 
GeneralRe: JAVA program to check please answer Pin
vivek8866-Oct-10 0:12
vivek8866-Oct-10 0:12 
GeneralRe: JAVA program to check please answer Pin
Richard MacCutchan6-Oct-10 0:20
mveRichard MacCutchan6-Oct-10 0:20 
GeneralRe: JAVA program to check please answer Pin
TorstenH.6-Oct-10 2:02
TorstenH.6-Oct-10 2:02 
GeneralRe: JAVA program to check please answer Pin
David Crow7-Oct-10 9:58
David Crow7-Oct-10 9:58 
AnswerRe: JAVA program to check please answer Pin
Luc Pattyn5-Oct-10 11:59
sitebuilderLuc Pattyn5-Oct-10 11:59 
GeneralRe: JAVA program to check please answer Pin
vivek8865-Oct-10 22:52
vivek8865-Oct-10 22:52 
GeneralRe: JAVA program to check please answer Pin
Nagy Vilmos5-Oct-10 23:15
professionalNagy Vilmos5-Oct-10 23:15 
Questionstructure equivalant in java Pin
trioum5-Oct-10 3:12
trioum5-Oct-10 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.