-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exception.txt
55 lines (52 loc) · 1.53 KB
/
Exception.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exception;
/**
*
* @author Madhu M P
*/
import java.util.*;
public class Exception {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Random random=new Random();
Scanner read=new Scanner(System.in);
int n;
System.out.println("Enter how many numbers u want to check");
int size=read.nextInt();
System.out.println("Enter the range of random integers to generate");
int r=read.nextInt();
boolean flag=false;
for(int i=0;i<size;i++)
{
flag=false;
n=random.nextInt(r);
int m=n;
while(n>0)
{
if(n%10==0)
{
flag=true;
break;
}
n/=10;
}
System.out.println("the random number is :"+m);
try
{
if(flag)
throw new ArithmeticException("Number contains zero");
System.out.println("the square of that number is: "+(m*m));
}
catch(ArithmeticException e)
{
System.out.println(e);
}
System.out.println("--------------------------------------------------------");
}}
}