Adding zero to a single digit number, Is it possible?

后端 未结 2 704
情话喂你
情话喂你 2021-01-14 02:43
public class MultiplicationTable {
public static void main (String[]a){

    int[] x;
    x = new int[10];
    int i;
    int n=0;

    for (i=0;i

        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 03:04

    Yes:

    String.format("%01d", x[i]*x[j]); is what you want.
    

    If you're familiar with printf in C then this will be familiar. If not, read the java reference on String.format format strings.

    Also, rather than 10 System.out.println statements, you can use a doubly nested loop with two counters. One to count which row you're in j and one for each column i.

提交回复
热议问题