如何编写一个while循环来验证用户输入正值 [英] How to Write a while loop that verifies that the user enters a positive value

查看:81
本文介绍了如何编写一个while循环来验证用户输入正值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

犯了大量错误,可能做错了。我正在使用visual studio和C#语言。 app.config

Getting a ton of errors and probably doing this all wrong. I'm using visual studio and C# language. app.config

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace positive
{
    class Program
    {
        static void Main(string[] args)
        {
            System.out.print("Enter a positive integer: ");
            number = scan.nextInt();
            while (number <= 0)
            
                System.out.print("Enter a positive integer: ");
                number = scan.nextInt();
        }
    }
}




推荐答案

您确定代码内容不是
Java
的?但不,你甚至没有声明变量。

Are you sure the code content is not Java? But no, you didn't even declare the variable.

顺便说一句,你需要了解Console.ReadLine(),Console.WriteLine()和  UInt32.TryParse()

Btw, you need to learn about Console.ReadLine(), Console.WriteLine() and UInt32.TryParse() .


这篇关于如何编写一个while循环来验证用户输入正值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆