大家好,我正在学习java以便在Android中编码,我有一些PHP经验,所以我被分配了一个练习,但找不到合适的循环,我尝试了else/if,虽然,但仍然找不到它,这是练习:
1- 提示用户输入学生人数,必须是可以被 10 整除的数字(数字 / 10)= 0 2- 检查用户输入,如果用户输入不能被 10 整除,请继续询问用户输入,直到他输入正确的输入
到目前为止我是如何编码的,while循环没有任何想法如何改进它或使它工作?
package whiledowhile;
import java.util.Scanner;
public class WhileDoWhile {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
/* int counter = 0;
int num;
while (counter <= 100) {
System.out.println("Enter number");
num = user_input.nextInt();
counter += num; // counter = counter + num
//counter ++ = counter =counter +1
}
System.out.println("Sum = "+ counter);
*/
int count = 0;
int num;
System.out.println("Please enter a number: ");
num = user_input.nextInt();
String ex;
do {
System.out.print("Wrong Number please enter again: " );
num++;
}
while(num/10 != 0 );
}
}