怎么写怎么写 急急急

 

public class Test {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			System.out.println("请输入一个整数:");
			int num=sc.nextInt();
			if(num%10==0){
				System.out.println("输入的数字为:"+num+",能被10整除,退出循环");
                        break;
			}else{
				System.out.println("输入的数字为:"+num);
			}
		}
	}
	
}	

代码如上,万望采纳。

使用java的do..while循环和输入即可解决,直接放到类中运行即可!

public static void main(String[] args) {
		int i = 0;
		Scanner scan = new Scanner(System.in);
		do {
			System.out.print("请输入一个数字:");
			i = scan.nextInt();
			System.out.println("输入的是:"+i);
		} while (i % 10 != 0);
		System.out.println("你输的" + i + "可以被10整除! 系统已退出!");
}

 

import java.utils.*;
public class Test{

    public static void main(String[] args){

        int a;
        Scanner in = new Scanner(System.in);
        while(true){
            System.out.println("请输入一个数");
            a = in.nextInt();
            if(a % 10 ==0){
                System.out.println(a+"能被10整除,退出循环。");
                break;
            }
        }
    }
}

请你先把你能写的最好程序分享出来, 我们就可以帮助你。 


import java.util.Scanner;

import static java.util.regex.Pattern.*;

/**
 * @Description: 输入的整数能被10整除就退出
 * @Author: Ansel
 * @DATE: 2021/5/28 5:31 PM
 **/
public class DivideByTen {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            System.out.print("请输入整数数字:");
            String string = scanner.nextLine();
            if (!compile("^[-\\+]?[\\d]*$").matcher(string).matches()) {
                //输入的不是整数数字重新输入
                continue;
            }
            int i = Integer.parseInt(string);
            if (i % 10 == 0) {
                System.out.println("输入的数字是:" + i + ", 能被10整除,循环退出!");
                break;
            }
            System.out.println("输入的数字是:" + i);
        }
    }

}

 

您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~

ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓

【电脑端】戳>>>  https://vip.csdn.net/askvip?utm_source=1146287632
【APP 】  戳>>>  https://mall.csdn.net/item/52471?utm_source=1146287632