Java Assignment
Java Assignment
Code
Prime.java
package primespackage; public
class Prime {
int temp;
if (temp == 0) { isPrime =
false; break;
return isPrime;
TwinsPrime.java
package assignment3;
//take input
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int n1 = sc.nextInt();
System.out.print("Enter second number: ");
int n2 = sc.nextInt();
sc.close();
Output
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
message ‘valid’ else ‘invalid’
Code
import JAVA.UTIL.NOSUchElementException;
import JAVA.UTIL.SCANNER;
import JAVA.UTIL.REGEX.MATCHER;
import JAVA.UTIL.REGEX.PATTERN;
Output