aspose file tools*
The moose likes Beginning Java and the fly likes hello Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

hello

lida abdi
Greenhorn

Joined: Aug 07, 2009
Posts: 2
I AM really sorry about my previous question,I want to express it SPECIFICALLY,This code dose not work properly,the str string is correct but i use 4 if.. else I think this part of this code dosen't work properly and it dese not have any output.Thank You

else if(src.endsWith("=")){


String str=t.getText();


for(int i=0;i<str.length()-1;i++){

char fn =str.charAt(i);

if(fn=='+'){

String s1=str.substring(0, i-1);
String s2=str.substring(i, str.length()-1);
int x=Integer.parseInt(s1);
int y=Integer.parseInt(s2);
String result=(x+y)+" ";

t.setText(result);
}





else if(fn=='-'){


String s1=str.substring(0, i-1);
String s2=str.substring(i, str.length()-1);
int x=Integer.parseInt(s1);
int y=Integer.parseInt(s2);
String result=(x-y)+" ";

t.setText(result);
}



else if(fn=='*'){

String s1=str.substring(0, i-1);
String s2=str.substring(i, str.length()-1);
int x=Integer.parseInt(s1);
int y=Integer.parseInt(s2);
String result=(x*y)+" ";

t.setText(result);
}

else if(fn=='/'){

String s1=str.substring(0, i-1);
String s2=str.substring(i, str.length()-1);
int x=Integer.parseInt(s1);
int y=Integer.parseInt(s2);
String result=(x/y)+" ";

t.setText(result);
}
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags.

One way to make code easier to understand and debug is to extract common functionality--here you have the *exact* same code in four places.

That aside, saying "I don't think it works" is useless (see ItDoesntWorkIsUseless) and in this case you only *think* it doesn't work.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14145
    
  18

Also, please use a meaningful subject line.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38787
    
  23
Closing as duplicate. Please continue any discussion here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hello