Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Its a loan calculator. I have a loop like

    public String loopresult(){
     for (int i=1; i<10; i++)
     return ((i) + "..........." + (i)*(i))
     }

It says this class must return String value. I tried

    valueOf.String((i) + "........" +(i)*(i)))

but didnt work.

I have to append it in txtArea.

    txtArea.append(loopresult())

what i want inside txtArea is like

2.........4 3.........9 so on, so it means this line will have int and string both.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
139 views
Welcome To Ask or Share your Answers For Others

1 Answer

Most likely what you intended was the following. You can only return one value, not multiple values. BTW You have a String already so your error message is confused.

 public String loopresult(){
     StringBuilder sb = new StringBuilder();
     for (int i=1; i<10; i++)
         sb.append(i + "..........." + i*i + "
");
     return sb.toString();
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...