Java Int to String

Sort by

recency

|

822 Discussions

|

  • + 0 comments

    The challenge for me was understanding what was available and already defined.

    After trying to create a new variable "n" and seeing an error that it already exists, that simplified the solution to just one line of code ;)

  • + 0 comments

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

    public class Solution {

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
    
        int n = scn.nextInt();
        // Object str = "" + n;
        Object str = String.valueOf(n);
    
        if (str instanceof String) {
            System.out.println("Good job");
        } else {
            System.out.println("Wrong answer");
        }
    
        scn.close();
    }
    

    }

  • + 0 comments

    I have tried in two diffrent ways in case i forget the method

    String s = ""+n;

    with method

    String s = String.valueOf(n);

    Hope it helped

  • + 0 comments

    It’s a confidence-building exercise for beginners and a solid reminder that mastering small fundamentals is key to progressing in Java programming. Telugu 365

  • + 0 comments

    String s = String.valueOf(n);