Práctica Básica de Codificación
Un número se almacena en una variable llamada num
en forma de string
. Sumar 2 al número almacenado. Puede utilizar los siguientes pasos:
- Convertir el valor de la cadena
num
a un entero y almacenarlo en una nueva variable entera llamadatemp
. - Sumar
2
al valor detemp
. - Convertir el valor de
temp
a unastring
y asignarlo a la variablenum
main.cs
123456789101112131415161718using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string num = "15"; // Write code below this line // Write code above this line Console.WriteLine(num); // Expected Output: 17 } } }
Utilizar Convert.ToInt32()
y Convert.ToString()
.
main.cs
1234567891011121314151617181920using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string num = "15"; // Write code below this line int temp = Convert.ToInt32(num); temp = temp + 2; num = Convert.ToString(temp); // Write code above this line Console.WriteLine(num); // Expected Output: 17 } } }
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Can you show me an example code for this task?
What happens if the string in `num` is not a valid number?
Can you explain how `Convert.ToInt32()` and `Convert.ToString()` work?
Awesome!
Completion rate improved to 1.59
Práctica Básica de Codificación
Desliza para mostrar el menú
Un número se almacena en una variable llamada num
en forma de string
. Sumar 2 al número almacenado. Puede utilizar los siguientes pasos:
- Convertir el valor de la cadena
num
a un entero y almacenarlo en una nueva variable entera llamadatemp
. - Sumar
2
al valor detemp
. - Convertir el valor de
temp
a unastring
y asignarlo a la variablenum
main.cs
123456789101112131415161718using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string num = "15"; // Write code below this line // Write code above this line Console.WriteLine(num); // Expected Output: 17 } } }
Utilizar Convert.ToInt32()
y Convert.ToString()
.
main.cs
1234567891011121314151617181920using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string num = "15"; // Write code below this line int temp = Convert.ToInt32(num); temp = temp + 2; num = Convert.ToString(temp); // Write code above this line Console.WriteLine(num); // Expected Output: 17 } } }
¡Gracias por tus comentarios!