-1
How can I put three values on the same line separated by space in C#? And then work with them?
Problem: https://www.urionlinejudge.com.br/judge/pt/problems/view/1079
-1
How can I put three values on the same line separated by space in C#? And then work with them?
Problem: https://www.urionlinejudge.com.br/judge/pt/problems/view/1079
2
You can use String.Split to separate into spaces and then convert to decimal array.
using System;
using System.Linq;
namespace Exemplo
{
public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Múltiplos valores em uma linha");
            string inp = Console.ReadLine();
            decimal [] valores = inp.Split(' ').Select(x=> decimal.Parse(x)).ToArray();//Ou foreach se preferir.
            Console.WriteLine(string.Join(", ",valores));
        }
    }
}
0
That’s a pretty easy way to do it:
using System;
namespace uri
{
    class Program
    {
        static void Main(string[] args)
        {  
            string[] texto = Console.ReadLine().Split(" ");
            int n1 = int.Parse(texto[0]), n2 = int.Parse(texto[1]), n3 = int.Parse(texto[2]);
            Console.WriteLine("n1 = "+n1+", n2 = "+n2+", n3 = "+n3);        
        }
    }
}
Browser other questions tagged c#
You are not signed in. Login or sign up in order to post.