javau3p2

import java.util.*; class LengthMatchException extends Exception { public LengthMatchException(String s) { super(s); } } public class pro32 { public static void main(String ar[]) { Scanner sc=new Scanner(System.in); try { String name; int size,len; System.out.println("Enter a size"); size=sc.nextInt(); System.out.println("Enter a name"); name=sc.next(); len=name.length(); if(size!=len) { throw new LengthMatchException("Length not match "); } } catch(LengthMatchException e) { System.out.println(e.getMessage()); } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.