Question Index

Write program to prefix spaces to the given input string so that it is at least 10 characters in length. If the input string is "Merit", whose length is 5, then 5 spaces should to be added before. If the length is greater than or equal to 10, then no spaces need to be added.

Input (excluding the double quotes) Output (excluding the double quotes, they are only placed to show the spaces)
"Merit" "     Merit"
"Campus" "    Campus"
"1234567890" "1234567890"
"Merit Campus" "Merit Campus"
"Hello Merit Campus" "Hello Merit Campus"
"" {EMPTY STRING} null
null null

class PrefixSpaces
    public static void main(String s[])
        String input = "Campus";
        String result = prefixSpaces(input);


    public static String prefixSpaces(String input)




Topic: Java equals method vs == Operator

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App