सीधे मुख्य सामग्री पर जाएं

HackerRank Java Int to String Problem Solution


HackerRank Java Int to String Problem Solution





Problem :

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
Solution:
import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
   
  try{
      
      Scanner scanner = new Scanner(System.in);
      int n = scanner.nextInt();
      String s =""
      
      if(n>=-100 && n<=100){
          s = Integer.toString(n);
      }
      
      if(n==Integer.parseInt(s)){
          System.out.println("Good job");
      }
      else{
           System.out.println("Wrong answer");
      }
      
  }
  
  catch(Exception e) {
       System.out.println("Unsuccessful");
      
  }
        
    }
}

टिप्पणियाँ

इस ब्लॉग से लोकप्रिय पोस्ट