-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.java
More file actions
45 lines (40 loc) · 1.04 KB
/
Copy pathexception.java
File metadata and controls
45 lines (40 loc) · 1.04 KB
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
import java.util.Scanner;
class Stringdemo{
String st;
int num,changedNum;
void setNum(int n)throws exception
{
if(n<0){
throw "number is lesser than 0";
}
num=n;
}
void setString(String str)throws exception
{
if(str.length<10){
throw "Invalid string length must be greater than 10";
}
st=str;
}
void changeNum(String n)throws NumberFormatException
{
changedNum=Integer.parseInt(n);
}
void show(){
System.out.println("Number:"+num+"\nString:"+st+"\nConverted-number:"+changedNum);
}
}
public class exception{
public static void main(){
Scanner sc = new scanner(System.in);
Stringdemo ob = new Stringdemo();
try{
System.out.print("Enter a number:");
int num = sc.nextInt();
System.out.print("Enter a string:");
String st = sc.nextLine();
System.out.print("Enter a number-string:");
st = sc.nextLine();
}
}
}