Create a method print a string If type is not string then throw exception and retry 3 times
public class Test { static String printString(String a){ return a; } static void printString(int a) throws Exception{ throw new Exception("This is not a string"); } public static void main (String[] args) throws Exception { int i = 0; while(i < 3){ try{ printString(3); } catch(Exception e){ System.out.println(e.getMessage()); i++; } } printString("this is a string"); } }