如何在伪代码中编写 hasnextInt()

how to write hasnextInt() in Pseudocode

我是 Java 的新手,我需要编写一个程序来验证用户输入是否为整数。但是,我也需要为它编写一个算法。我们通常如何在伪代码中编写 hasNextInt()? 我写了类似的东西:

WHILE (IF INPUT IS NOT INTEGER)
    OUTPUT "Error, enter integer only: "
    (how do you write this?)
END WHILE
n1 := INPUT

我是否可以改进此伪代码以使其更合理?

//enter code here
while(!read.hasNextInt())    // check if user input is an integer, if it is not integer, run the loop
{
    System.out.print("Error, enter integer only: ");    
    read.next();    // prompt user to enter input again
}
    n1 = read.nextInt();    // get the data from the input and assign into n1

伪代码有多种形式。因此,只要您的代码保持一致,就有多种编写方法。

为了与伪代码的其余部分保持一致,例如,read.next() 可以写成 CONTINUEIGNORE INPUT