-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargeOdd.java
More file actions
32 lines (29 loc) · 799 Bytes
/
LargeOdd.java
File metadata and controls
32 lines (29 loc) · 799 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
import java.util.Scanner;
public class LargeOdd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int num = Integer.parseInt(s);
int maxOdd = 0;
boolean founMax = false;
if(num%2 != 0){
System.out.println(num);
}else{
while(num > 0){
int n = num%10;
if(n%2 != 0){
maxOdd = Math.max(n, maxOdd);
founMax = true;
}else{
continue;
}
}
}
String str = String.valueOf(s);
if(founMax){
System.out.println(maxOdd);
}else{
System.out.println(-1);
}
}
}