You are given an integer , you have to convert it into a string.
Please complete the partially completed code in the editor. If your code successfully converts into a string the code will print "Good job". Otherwise it will print "Wrong answer".
can range between to inclusive.
Sample Input 0
100
Sample Output 0
Good job
Sample Input 1
67
Sample Output 1
Good Job
Sample Input 3
200
Sample Output 3
Wrong answer
Java Program:
import java.util.*;
import java.security.*;
public class Solution {
public static void main(String[] args) {
DoNotTerminate.forbidExit();
try {
Scanner in = new Scanner(System.in);
int n = in .nextInt();
in.close();//String s=???; Complete this line below
String s = String.valueOf(n); //Write your code here
if (n == Integer.parseInt(s)) {
System.out.println("Good job");
}
else {
System.out.println("Wrong answer.");
}
}
catch (DoNotTerminate.ExitTrappedException e) {
System.out.println("Unsuccessful Termination!!");
}
}
} //The following class will prevent you from terminating the code using exit(0)!
class DoNotTerminate {
public static class ExitTrappedException extends SecurityException {
private static final long serialVersionUID = 1;
}
public static void forbidExit() {
final SecurityManager securityManager = new SecurityManager() {
@Override
public void checkPermission(Permission permission) {
No comments:
Post a Comment