+ 1

Check my code plz.

Hey who can help me check this code as the question is as follows Write a program that prompts the user to enter an integer number and convert the int to String using Integer class This is my attempt: package convertinttostring; import java.util.Scanner; public class ConvertIntToString { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an Integer value: "); Integer One = input.nextInt(); String Tow = One.toString(); System.out.println("Convet Int to String will be as: " + Tow); } } And the run was as the follows: Enter an Integer value: 11 Convert Int to String will be as: 11 So my attempt is True or False?

26th Feb 2021, 12:29 PM
Lisa John
Lisa John - avatar
3 Respostas
+ 1
ToString is a method of Object i think, so probably not what you are supposed to do. Search Integer class in Java documentation and see if there is another method. Besides that Tow is obviously a string by definition
26th Feb 2021, 1:44 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
You can.Integer class has a method of toString() to convert to string.. edit: you already did Integer.toString(num);
26th Feb 2021, 2:34 PM
Jayakrishna 🇮🇳
0
please show me how I can make this in a code? Jayakrishna🇮🇳
26th Feb 2021, 3:12 PM
Lisa John
Lisa John - avatar