Java Output Formatting

  • + 0 comments
    System.out.println("================================");
                int totalLength = 15;
                for(int i=0;i<3;i++){
                    String s1=sc.next();
                    int x=sc.nextInt();
                     //Complete this line
                    String formatnumber = String.format("%03d",x);
                    int spaceNeeded = totalLength - s1.length();
                    StringBuilder spaces = new StringBuilder();
                    for (int j = 0; j < spaceNeeded; j++) {
                        spaces.append(" ");
                    }
                    String finalString = s1+ spaces + formatnumber;
    

    undefined System.out.println(finalString); } System.out.println("=========== `=====================");