Problem statement:
You are given an integer n, you have to convert it into a string.
If your code successfully converts n into a string s the code will print "Good job". Otherwise it will print "Wrong answer".
n can range between 100 to 100 inclusive.
Sample Input 0
100
Sample Output 0
Good job
public class ConvertIntToString {
public static void main(String[] args) {
int n = 100;
//String s = String.valueOf(n); // method - 1
//String s = "" + n; // method - 2
String s = Integer.toString(n); // method - 3
if (n == Integer.parseInt(s)) {
System.out.println("Good Job");
} else {
System.out.println("Wrong Answer");
}
}
}
You are given an integer n, you have to convert it into a string.
If your code successfully converts n into a string s the code will print "Good job". Otherwise it will print "Wrong answer".
n can range between 100 to 100 inclusive.
Sample Input 0
100
Sample Output 0
Good job
public class ConvertIntToString {
public static void main(String[] args) {
int n = 100;
//String s = String.valueOf(n); // method - 1
//String s = "" + n; // method - 2
String s = Integer.toString(n); // method - 3
if (n == Integer.parseInt(s)) {
System.out.println("Good Job");
} else {
System.out.println("Wrong Answer");
}
}
}
Output:
Good Job
No comments:
Post a Comment