Shreyas arya

Generation

generate functionFri, 10 Feb 2023

Create a method print a string If type is not string then throw exception

class StringPrinter { public void printString(String s){ if(!(s instanceof String)){ throw new RuntimeException("Invalid String"); } System.out.println(s); } }

Questions about programming?Chat with your personal AI assistant