Java Output Formatting

Sort by

recency

|

1458 Discussions

|

  • + 0 comments

    import java.util.Scanner;

    public class Solution {

    public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            System.out.println("================================");
            for(int i=0;i<3;i++){
                String s1=sc.next();
                int x=sc.nextInt();
                //Complete this line
                System.out.printf("%-15s%03d\n",s1,x);
            }
    
                        %
            System.out.println("================================");
    
    }
    

    }

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
    
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
            System.out.println("================================");
            for (int i = 0; i < 3; i++) {
            String s1 = sc.next();
            int x = sc.nextInt();         
            System.out.printf("%-15s%03d\n", s1, x);
            }
            System.out.println("================================");
    
    }
    

    }

  • + 0 comments

    It really highlights how formatting can control the presentation of output—especially useful in console-based applications. 11xplay

  • + 0 comments

    lol guys this is what i did import java.util.Scanner;

    public class Solution { static void f1(String s){ // String s = "cpp 65"; String[] parts = s.split(" "); String str = parts[0]; String num = parts[1]; String fin = ""; if (num.length()==2){ fin = "0" + num; } else if (num.length()==1){ fin = "00" + num; } else { fin = num; } int space = 15-str.length(); String gap = ""; for(int i=0;i

  • + 0 comments

    Java is such a powerful and versatile programming language! Its platform independence and strong object-oriented features make it a go-to choice for building everything from desktop applications to enterprise systems and Android apps. 11xplay