Win a copy of The Java Performance Companion this week in the Performance forum!
    Bookmark Topic Watch Topic
  • New Topic

hello

 
lida abdi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closing as duplicate. Please continue any discussion here.
 
    Bookmark Topic Watch Topic
  • New Topic