-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathFindLargestNumber.java
More file actions
36 lines (32 loc) · 1012 Bytes
/
FindLargestNumber.java
File metadata and controls
36 lines (32 loc) · 1012 Bytes
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class FindLargestNumber {
static Integer findMax(String str, int i,int max){
String temp = str.substring(0,i)+str.substring(i+1, str.length());
if(Integer.parseInt(temp)>max){
return Integer.parseInt(temp);
}
else{
return max;
}
}
static Integer solve(String str,String num){
int max=0;
int i=0;
while(i<str.length()){
if(String.valueOf(str.charAt(i)).equals(num)){
max=findMax(str,i,max);
}
i++;
}
return max;
}
public static void main(String[] args)throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str = bf.readLine();
String num = bf.readLine();
int res = solve(str,num);
System.out.println("res:-"+res);
}
}