Home > OS >  I am making an app which shows table of a number but it only shows last calculation, i want all the
I am making an app which shows table of a number but it only shows last calculation, i want all the

Time:04-06

CodeHi there, I am trying to make an app which shows the table of a number given by user. I am able to get only last answer of a table, for example, it only shows 5*10=50 but i want whole table from 1 to 10. For reference, I've also attached some images of the app. please help.

CodePudding user response:

i think your logic is wrong plz check you loop statement. If you want whole table result from 1 to 10 then you should start you loop from 1 to 10 with increment.

for(int i = 1; i < = 10; i  ) {
            Log.d((input " * " i " = "  input * i );    
        }
Thanks

CodePudding user response:

Here is simple solution for java developers

int a  = 1; //User Input
StringBuilder table = new StringBuilder();
for(int i = 1; i <= 10; i  ) {
    table.append(a).append(" * ").append(i).append(" = ").append(a * i).append("\n");
}
String finalTable = table.toString();
  • Related