Java Output Formatting

Sort by

recency

|

1428 Discussions

|

  • + 0 comments

    It’s no wonder it's been a top choice for everything from web apps to large-scale enterprise systems for decades! m.ekbet11.com

  • + 0 comments

    Simple Solution

    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();
                int l=s1.length();
                System.out.print(s1+" ".repeat(15-l));
                if(x<10){
                    System.out.println("00"+x);
                }
                else if(x<100){
                    System.out.println("0"+x);
                }
                else{
                    System.out.println(x);
                }
    
            }
            System.out.println("================================");
    
    }
    

    }

  • + 1 comment

    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();
    
                System.out.printf("%-15s%03d%n",s1,x);
            }
            System.out.println("================================");
    
    }
    

    }

  • + 0 comments

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

    public class Main {

    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 word = sc.next();
            int num = sc.nextInt();
            if(word.length() <= 10 && num >= 0 && num <= 999) {
                System.out.printf("%-15s%03d\n", word, num);
            }
        }
        System.out.println("================================");
    }
    

    }

  • + 0 comments

    Java is one of the most widely used and versatile programming languages in the world. Skysetx com