Saturday, April 18, 2015

Display Strings in Between * Lines

Here is the code to display the string in the * column using loop for any string provided by user.



import java.util.Scanner; //Scanner Class
public class StringDisplay {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the String:- \t");
        String s = sc.next(); //Getting String Input from user
        int n = s.length(); //Finding Length of String
        for(int i=1;i<n+5;i++) //Running Loop
        {
            System.out.print("*");
        }
        System.out.println();
        System.out.println("**"+s+"**");
        for(int i=1;i<n+5;i++)
        {
            System.out.print("*");
        }
        System.out.println();
    }
}

No comments:

Post a Comment