Java Int to String

Sort by

recency

|

802 Discussions

|

  • + 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");
        }
    
  • + 0 comments

    String s = n+"";

    //second way String s2 = String.valueOf(n);

    //third way String s3 = Integer.toString(n);

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
       Scanner sc = new Scanner (System.in);
       int n = sc.nextInt();
       String s = Integer.toString(n); 
       if(n >= -100 || n <= 100 && s == Integer.toString(n)){
        System.out.println("Good job");
       } else {
        System.out.println("Wrong Answer");
       }
    }
    

    }