YavorGrancharov

Fit_String_in_20_Chars

Jan 4th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Fit_String_in_20_Chars {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.  
  7.         String input = console.nextLine();
  8.  
  9.         if (input.length() >= 20) {
  10.             System.out.println(input.substring(0, 20));
  11.         }
  12.         else {
  13.             for (int i = 0; i < 20; i++) {
  14.                 if (i >= input.length()) {
  15.                     System.out.print("*");
  16.                     continue;
  17.                 }
  18.  
  19.                 System.out.print(input.charAt(i));
  20.             }
  21.         }
  22.     }
  23. }
Add Comment
Please, Sign In to add comment