Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int antal;
- while (true)
- {
- Console.Write("Hur många heltal vill du skriva?: ");
- try
- {
- antal = int.Parse(Console.ReadLine());
- if (antal > 0)
- {
- break;
- }
- else
- {
- throw new Exception("Talet är mindre än 1.");
- }
- }
- catch (Exception e)
- {
- Console.Clear();
- Console.WriteLine(e.Message + " Vänligen försök igen...");
- continue;
- }
- }
- int[] array = new int[antal];
- for (int i = 0; i < array.Length; i++)
- {
- while (true)
- {
- Console.Write($"Tal {i + 1}: ");
- try
- {
- array[i] = int.Parse(Console.ReadLine());
- break;
- }
- catch (Exception e)
- {
- Console.Clear();
- Console.WriteLine(e.Message + " Vänligen försök igen...");
- continue;
- }
- }
- }
- for (int i = array.Length - 1; i >= 0; i--)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- Console.ReadKey();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement