Java Int to String

Sort by

recency

|

804 Discussions

|

  • + 0 comments

    this my answer ` 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 num = Integer.parseInt(scanner.nextLine());
    
            if (num < -100 || num > 100) {
                throw new NumberFormatException();
            }
    
            System.out.println("Good job");
    
        } catch (NumberFormatException e) {
            System.out.println("Wrong answer");
        }
    }
    

    } `

  • + 0 comments

    This question was not confusing at all. Very clear !!!

  • + 0 comments

    **Only one line code **

    String s = Integer.toString(n);
    
  • + 0 comments

    i am totally confused. because of i am writing again and again if condition unnecessary. after i realised what kind of mistake doing again nd again. only i have to write one line code.

    String s=Integer.toString(n);

    that's all set.

  • + 0 comments

    Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = Integer.toString(n);

        if (s.equals(Integer.toString(n)) && (n >= -100 || n <= 100 )) {
            System.out.println("Good job");
        } else {
            System.out.println("Wrong Answer");
        }