0% found this document useful (0 votes)
40 views3 pages

This Study Resource Was: CSE 1007 Lab Activity-6

Learn more about Scribd Membership Home Saved Bestsellers Books Audiobooks Snapshots Magazines Documents Sheet Music Document details Title (Required) 001 Description (Required)Invalid, qsqwfeasdbfxngx Error Please provide a description to continue Make this document private Show Advanced Settings Delete Done Document details

Uploaded by

Penchal Doggala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

This Study Resource Was: CSE 1007 Lab Activity-6

Learn more about Scribd Membership Home Saved Bestsellers Books Audiobooks Snapshots Magazines Documents Sheet Music Document details Title (Required) 001 Description (Required)Invalid, qsqwfeasdbfxngx Error Please provide a description to continue Make this document private Show Advanced Settings Delete Done Document details

Uploaded by

Penchal Doggala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSE 1007

Lab Activity-6
Name: S Jayakishore Reg No: 16BIS0041

Write a program to demonstrate the knowledge of students in Java Exception handling.


Read the Register Number and Mobile Number of a student. If the Register Number does not
contain exactly 9 characters or if the Mobile Number does not contain exactly 10 characters,
throw an IllegalArgumentException. If the Mobile Number contains any character other than
a digit, raise a NumberFormatException. If the Register Number contains any character other
than digits and alphabets, throw a NoSuchElementException. If they are valid, print the

m
message ‘valid’ else ‘invalid’.

e r as
co
CODE:

eH w
import java.util.*;

o.
import java.util.regex.*;
rs e
ou urc
import java.lang.*;
public class lab6{
o
aC s

public static void main(String[] args)


v i y re

{
ed d

int a=0,b=0;
ar stu

String regNo,mobNo;
Scanner in=new Scanner(System.in);
sh is

System.out.println("Enter the registration number: ");


Th

regNo=in.nextLine();
try{if(regNo.length()!=9)
{
a=1;
throw new IllegalArgumentException("Length of Registration
number should be 9");
}}
catch(Exception e)

https://www.coursehero.com/file/39866238/lab6-16bis0041pdf/
{
System.out.println(e);}
try{if(!Pattern.matches("[0-9]*[a-z]*[A-Z]*[0-9]*[a-z]*[A-Z]*",regNo))
{
a=1;
throw new NoSuchElementException("Registration number
should have only numbers and alphabets");
}}
catch(Exception e){
System.out.println(e);

m
e r as
}

co
eH w
System.out.println("Please enter the mobile number: ");

o.
mobNo=in.nextLine();
rs e
ou urc
try{
if(mobNo.length()!=10)
o

{
aC s
v i y re

b=1;
throw new IllegalArgumentException("Lengths do not match");
ed d

}}
ar stu

catch(Exception e)
{
sh is

System.out.println(e);
Th

}
try{if(!Pattern.matches("[0-9]+",mobNo))
{
b=1;
throw new NumberFormatException("mobile number should
contain only numbers!!");
}}
catch(Exception e){

https://www.coursehero.com/file/39866238/lab6-16bis0041pdf/
System.out.println(e);
}
if(a==1)
System.out.println("Invalid registration number");
else if(a==0)
System.out.println("Valid registration number");
if(b==1)
System.out.println("Invalid mobile number");
else if(b==0)

m
System.out.println("Valid mobile number");

e r as
co
}}

eH w
o.
OUTPUT:
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th

https://www.coursehero.com/file/39866238/lab6-16bis0041pdf/

Powered by TCPDF (www.tcpdf.org)

You might also like