Advertisement
vencinachev

Java-RepeatText-Exceptions

Mar 18th, 2021
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. class RepeatText {
  2.    public static void main(String[] args){
  3.        try {
  4.            int count = Integer.parseInt(args[1]);
  5.            for (int i = 0; i < count; i++){
  6.           System.out.println(args[0]);
  7.            }
  8.        } catch (NumberFormatException ex1){
  9.           System.out.println("Second argument must be positive number!");
  10.        } catch (ArrayIndexOutOfBoundsException ex2) {
  11.            try {
  12.              System.out.println(args[0]);
  13.            }
  14.            catch (ArrayIndexOutOfBoundsException ex3) {
  15.                 System.out.println("No arguments!");
  16.            }
  17.        }
  18.    }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement