Java程序检查数字的所有数字是否将其除
要检查数字的所有数字是否将其除,Java代码如下:
示例
import java.io.*;
public class Demo{
static boolean divisibility_check(int val, int digit){
return (digit != 0 && val % digit == 0);
}
static boolean divide_digits(int val){
int temp = val;
while (temp > 0){
int digit = val % 10;
if ((divisibility_check(val, digit)) == false)
return false;
temp /= 10;
}
return true;
}
public static void main(String args[]){
int val = 150;
if (divide_digits(val))
System.out.println("数字的所有数字将数字完全除。");
else
System.out.println("All the digits of the number are not divided by the number
completely.");
}
}输出结果
All the digits of the number are not divided by the number completely.
名为Demo的类包含一个名为“divisibility_check”的函数,该函数具有两个参数-数字和数字。此函数根据返回的输出是true还是false来返回布尔值。它检查数字是否不为0,以及数字除以数字的位数是否被完全除。
另一个名为“divide_digits”的函数是一个布尔函数,它以数字作为参数。此功能检查数字中的所有数字是否将数字完全除。在主函数中,定义了一个数字值,并使用该值调用该函数,如果返回“true”,则显示相关消息。如果不是,那么它会显示一条消息,指出数字不能被完全除。
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短