第一题
package ch3choose.exer;
import java.util.Scanner;
/**
* zhengbin
* 2023/5/11 20:55
*/
public class Exer1 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter a b c :");
double a=input.nextDouble();
double b=input.nextDouble();
double c=input.nextDouble();
double r1=0.0;
double r2=0.0;
//判断△的值是否大于 0 如果小于 0 则该方程无实数根
double delta=(Math.pow(b,2)-4*a*c) ;
if(delta<0){
System.out.println("THe equation has no real roots .");
}
else if(delta==0){
r1=r2=((-1)*b)/(2*a);
System.out.println("THe equation has one root "+r1);
}
else{
r1=((-1)*b+Math.pow(delta,0.5))/(2*a);
r2=((-1)*b-Math.pow(delta,0.5))/(2*a);
System.out.println("THe equation has two roots "+r1+"and "+r2);
}
}
}
第二题
package ch3choose.exer2;
import java.util.Scanner;
/**
* zhengbin
* 2023/5/11 21:11
*/
public class Exer2 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter three numbers: ");
// System.out.println("Enter first number:");
int []arr=new int[3];
for (int i = 0; i < arr.length; i++) {
System.out.println("Enter the"+ (i+1)+" number:");
while (true){
int a=input.nextInt();
if(a<10&&a>-10){
arr[i]=a;
break;
}
else{
System.out.println("Enter the"+ (i+1)+" number:");
}
}
}
int sum=0;
for (int j : arr) {
sum += j;
}
System.out.println("The sum is :"+sum);
}
}
第三题
package ch3choose.exer3;
import java.time.Year;
import java.util.Scanner;
/**
* 2023/5/11 21:25
* 求一元一次方程组的解
*/
public class Exer3 {
public static void main(String[] args) {
System.out.println("请输入方程式");
System.out.println("ax+by=e");
System.out.println("cx+dy=f");
System.out.println("中 x y 的解");
Scanner input=new Scanner(System.in);
System.out.println("请输入 a b c d e f 的值");
double [] arr=new double[6]; //用数组来存放变量
for (int i = 0; i < arr.length; i++) {
arr[i]=input.nextDouble();
}
double v = arr[0] * arr[3] - arr[1] * arr[2];
if(v==0){
System.out.println("这个方程组无解!");
}
else {
double x = (arr[3] * arr[4] - arr[1] * arr[5]) / v;
double y = (arr[5] * arr[0] - arr[4] * arr[2]) / v;
System.out.println("X = "+x+" , Y = "+ y);
}
}
}
第四题
package ch3choose.exer4;
/**
* 2023/5/11 21:41
* 随机月份获取
*/
public class Exer4 {
public static void main(String[] args) {
int month=(int)(Math.random()*12)+1;
System.out.println("你输入的数字是:"+month);
switch (month) {
case 1 -> System.out.println("January.");
case 2 -> System.out.println("February.");
case 3 -> System.out.println("March.");
case 4 -> System.out.println("April.");
case 5 -> System.out.println("May.");
case 6 -> System.out.println("June.");
case 7 -> System.out.println("July.");
case 8 -> System.out.println("August.");
case 9 -> System.out.println("September.");
case 10 -> System.out.println("October.");
case 11 -> System.out.println("November.");
case 12 -> System.out.println("December.");
}
}
}
第五题
package ch3choose.exer5;
import org.junit.Test;
import java.util.Scanner;
/**
* zhengbin
* 2023/5/11 21:58
* 给出将来的日期
*/
public class Exer5 {
public static void main(String[] args) {
System.out.print("请输入今天是星期几?(0 表示星期天): ");
Scanner input=new Scanner(System.in);
// int days=input.nextInt();
int today=input.nextInt();
while (true) {
// int today=input.nextInt();
if(today>6||today<0)
{
System.out.println("输入错误,请重新输入:");
today=input.nextInt();
}
else{
switch (today) {
case 0 -> System.out.println("今天是星期天");
case 1 -> System.out.println("今天是星期一");
case 2 -> System.out.println("今天是星期二");
case 3 -> System.out.println("今天是星期三");
case 4 -> System.out.println("今天是星期四");
case 5 -> System.out.println("今天是星期五");
case 6 -> System.out.println("今天是星期六");
default -> {
}
}
break;
}
}
System.out.println("请输入未来的天数:");
int days=input.nextInt();
int weekday=(today+days)%7;
switch (weekday) {
case 0 -> System.out.println("再过 "+days+" 天是星期天");
case 1 -> System.out.println("再过 "+days+" 天是星期一");
case 2 -> System.out.println("再过 "+days+" 天是星期二");
case 3 -> System.out.println("再过 "+days+" 天是星期三");
case 4 -> System.out.println("再过 "+days+" 天是星期四");
case 5 -> System.out.println("再过 "+days+" 天是星期五");
case 6 -> System.out.println("再过 "+days+" 天是星期六");
default -> {
}
}
}
}
第六题
package ch3choose.exer6;
import java.util.Scanner;
/*
* 孤鸿
* 健康应用:BMI
* */
public class Exer6 {
public static void main(String[] args) {
//BMI计算方式:体重/身高的平方 小于18.5 偏瘦 18.5-23.9 正常 大于24为超重 大于等于28为肥胖
// 1英尺=0.3048米
// 1英寸=0.0254米
// 1磅=0.45359237千克
Scanner input=new Scanner(System.in);
System.out.println("Enter weight in pounds:");
int pound= input.nextInt(); //磅
System.out.println("Enter foot");
int foot=input.nextInt(); //英尺
System.out.println("Enter inches");
int inch=input.nextInt(); //英寸
double kilogram=pound*0.45359237;
double meters=foot*0.3048+inch*0.0254;
double BMI=kilogram/(Math.pow(meters,2));
System.out.println("BMI is " +BMI);
if(BMI<18.5){
System.out.println("偏瘦!");
}
else if(BMI>=18.5&&BMI<=24){
System.out.println("正常!");
}
else if (BMI>24&&BMI<28)
{
System.out.println("超重!");
}
else{
System.out.println("肥胖!");
}
}
}
第八题
package ch3choose.exer8;/*
* 孤鸿
* 对三个整数排序
* 2023/5/12
*/
import java.util.Scanner;
public class Exer8 {
public static void main(String[] args) {
System.out.println("请输入三个整数:");
Scanner input=new Scanner(System.in);
int [] arr=new int[3]; //定义一个数组存放三个整数
for (int i = 0; i < arr.length; i++) {
arr[i]=input.nextInt();
}
//从小到大排序
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
if(arr[i]<arr[j]){
int tmp=arr[i];
arr[i]=arr[j];
arr[j]=tmp;
}
}
}
System.out.print("从小到大的排序为: ");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+"\t");
}
}
}
第九题
package ch3choose.exer9;
import java.util.Scanner;
/**
* 孤鸿
* 2023/5/12 21:56
*/
public class Exer9 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the first 9 digits of an ISBN as an integer: ");
String digits = input.next();
int sum = 0;
while (true) { //判断输入的数字是否是一个 9 位数字
if (digits.length() == 9) {
char[] arr = digits.toCharArray();
boolean isValid = true; //定义一个标记
for (int i = 0; i < arr.length; i++) {
if (!Character.isDigit(arr[i])) { //判断输入的数据是否全部都是数字
isValid = false;
break;
}
sum += (arr[i] - '0') * (i + 1);
}
if (isValid) {
break;
}
}
System.out.println("Invalid input, please enter 9 digits: ");
digits = input.next();
}
String lastDigit;
if (sum % 11 == 10) { //如果取余结果是 10 返回最后一位为 X
lastDigit = "X";
} else {
lastDigit = Integer.toString(sum % 11);
}
String isbn = digits + lastDigit; //连接字符串数据.
System.out.println("The ISBN-10 number is: " + isbn);
}
}
第十题
package ch3choose.exer10;/*
* 孤鸿
* 2023/5/12
*/
import java.util.Scanner;
public class Exer10 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int num1=(int)(Math.random()*100);
int num2=(int)(Math.random()*100);
System.out.println(num1+" + "+ num2+" = "+(num1+num2));
}
}
第十一题
package ch3choose.exer11;
import java.util.Scanner;
/**
* 孤鸿
* 给出某月份的天数
* 2023/5/13 10:09
*/
public class Exer11 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入月份:");
int month= input.nextInt();
while(true){ //年份的判断 只能是 1-12 月份
if(month<1||month>12){
System.out.println("输入的月份有误;请重新输入");
month=input.nextInt();
}else{
break;
}
}
System.out.println("请输入年份:"); //设定年份的有效期范围
int year=input.nextInt();
while(true){
if(year<1||year>9999){
System.out.println("输入的年份有误;请重新输入");
year=input.nextInt();
}else{
break;
}
}
switch (month) {
case 1, 3, 5, 7, 8, 10, 12 -> System.out.println(year + " 年 " + month + " 月有 31 天");
case 2 -> {
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
System.out.println(year + " 年 " + month + " 月有 29 天");
} else {
System.out.println(year + " 年 " + month + " 月有 28 天");
}
}
case 4, 6, 9, 11 -> System.out.println(year + " 年 " + month + " 月有 30 天");
default -> {
}
}
}
}
第十二题
package ch3choose.exer12;
import java.util.Scanner;
/**
* 孤鸿
* 回文数 提示输入一个三位数,判断是否是回文数
* 2023/5/13 10:45
*/
public class Exer12 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入一个三位数:");
int num=input.nextInt();
while(true){ //判断输入的是否是一个三位数.
//int x=Integer.toString(num).length();
if(Integer.toString(num).length()==3)
{
break;
}
else{
System.out.println("输入错误,请重新输入:");
num=input.nextInt();
}
}
if((num%10)==(num/100)){
System.out.println(num +" 是一个回文数");
}
else{
System.out.println(num +" 不是一个回文数");
}
}
}
第十三题
package ch3choose.exer13;/*
* 孤鸿
* 2023/5/13
*/
import java.util.Scanner;
public class Exer13 {
static double tax;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("(0-single filer,1-married jointly or qualifying widow(er)," +
"2-married separately,3-head of household) " +
"Enter the filing status:");
int status = input.nextInt();
System.out.println("Enter the taxable income: ");
double income = input.nextDouble();
if (status >= 0 && status < 4) {
tax1(status, income);
} else {
System.out.println("Error : invalid status");
System.exit(1);
}
System.out.println("Tax is " + (int) (tax * 100) / 100.0);
}
//定义一个静态方法用来计算个人所得税
public static void tax1(int status, double income){
//声明一个二维数据用于存放根据不同的婚姻情况的起征额度
int[][] arr = new int[][]{{8350, 33950, 82250, 171550, 372950}, {16700, 67900, 137050, 208850, 372950}, {8350, 33950, 68525, 104425, 186475}, {11950, 45500, 117450, 190200, 372950}};
// double tax;
if (income <= arr[status][0]) {
tax = income * 0.1;
} else if (income <= arr[status][1]) {
tax = arr[status][0] * 0.1 + (income - arr[status][0]) * 0.15;
} else if (income <= arr[status][2]) {
tax = arr[status][0] * 0.1 + (arr[status][1] - arr[status][0]) * 0.15 + (income - arr[status][1]) * 0.25;
} else if (income <= arr[status][3]) {
tax = arr[status][0] * 0.1 + (arr[status][1] - arr[status][0]) * 0.15 + (arr[status][2] - arr[status][1]) * 0.25 + (income - arr[status][2]) * 0.28;
} else if (income <= arr[status][4]) {
tax = arr[status][0] * 0.1 + (arr[status][1] - arr[status][0]) * 0.15 + (arr[status][2] - arr[status][1]) * 0.25 + (arr[status][3] - arr[status][2]) * 0.28 + (income - arr[status][3] * 0.33);
} else {
tax = arr[status][0] * 0.1 + (arr[status][1] - arr[status][0]) * 0.15 + (arr[status][2]- arr[status][1]) * 0.25 + (arr[status][3] - arr[status][2]) * 0.28 + (arr[status][4] - arr[status][3]) * 0.33 + (income - arr[status][4]) * 0.35;
}
}
}
第十四题
package ch3choose.exer14;/*
* 孤鸿
* 2023/5/13
* 猜硬币的正反面
*/
import java.util.Scanner;
public class Exer14 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int answer=(int)(Math.random()*2); //生成一个随机数
System.out.println("请输入硬币的正反面(0表示正面,1表示反面)");
int num=input.nextInt();
while (true){
if(num==0||num==1){
break;
}
else{
System.out.println("请输入硬币的正反面(0表示正面,1表示反面)");
num=input.nextInt();
}
}
if(answer==num){
System.out.println("您猜对了!");
}
else{
System.out.println("您猜错了!");
}
}
}
第十五题
package ch3choose.exer15;/*
* 孤鸿
* 彩票
* 2023/5/13
*/
import java.util.Scanner;
public class Exer15 {
public static void main(String[] args) {
int count = 0;
Scanner input=new Scanner(System.in);
//随机数公式
int answer=100+(int)(Math.random()*((999-100)+1));
System.out.println(answer);
System.out.println("请输入你的号码");
int num= input.nextInt();
String s=Integer.toString(answer);
System.out.println(answer);
while (true){ //
if(Integer.toString(num).length()==3){
break;
}
else{
num= input.nextInt();
}
}
if(num==answer){ //如果两个数字相等 直接输出中奖信息
System.out.println("奖金10000美元");
}else {
char[] arr = s.toCharArray(); //将中奖号码转换为字符数组
char[]arr1=Integer.toString(num).toCharArray(); //将你输入的号码转换为字符数组。
int j=0;
for (j = 0; j<arr1.length; j++) { //对两个数组进行比较
for (int i = 0; i < arr.length; i++) {
if ((arr1[j])== arr[i]) {
count++; //记录匹配上的字符的个数
break;
}
}
}
if(count==3){
System.out.println("你猜中了"+count+"个数字,奖金3000美元");
}else if(count>=1){
System.out.println("你猜中了"+count+"个数字,奖金1000美元");
}
else{
System.out.println("你猜中了"+count+"个数字,没有中奖");
}
}
}
}
第十六题
package ch3choose.exer16;/*
* 孤鸿
* 随机点
* 2023/5/15
*/
public class Exer16 {
public static void main(String[] args) {
int width=-100+(int)(Math.random()*((200)+1));
int height=-200+(int)(Math.random()*((400)+1));
if(width==0&&height==0){
System.out.println("当前坐标值为原点.");
}
else {
System.out.println("矩形的坐标值是:[" + width + "," + height + "]");
System.out.println("该矩形的面积为:" + Math.abs(width) * Math.abs(height));
}
}
}
第十七题(石头剪刀布游戏)
package ch03.exer17;
import java.util.Scanner;
/*
* 石头剪刀布游戏
*/
public class Exer17 {
public static void main(String[] args) {
int x=(int)(Math.random()*3); //生成一个0-2的一个随机数
Scanner input=new Scanner(System.in);
System.out.println("scissor(0),rock(1),paper(2) :");
int num=input.nextInt();
//判断输入的是否是正确的数字
while(true){
if(num>=0&&num<3){
break;
}else{
System.out.println("scissor(0),rock(1),paper(2) :");
num=input.nextInt();
}
}
//比较输赢
if(num-x==-1||num-x==2){
System.out.println("The computer is "+convert(x)+", You are "+convert(num)+". You won");
}
else if(num-x==0){
System.out.println("The computer is "+convert(x)+", You are "+convert(num)+" too. It is a draw");
}
else{
System.out.println("The computer is "+convert(x)+", You are "+convert(num)+". You lost");
}
}
//将电脑生成的随机数和用户输入的数字 转换为石头 剪刀 布
private static String convert(int x) {
switch (x){
case 0:
return "scissor";
case 1:
return "rock";
case 2:
return "paper";
default:
return "error";
}
}
}
第十八题
package b18;
import java.util.Scanner;
/**
* 孤鸿
* 题目:
* 2024/1/29 09:01
*/
public class exer18 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("请输入运输重量:");
double w= input.nextDouble();
if(w<=0){
System.out.println("Invalid input");
}
else if(w<=1)
{
System.out.println("运输成本为: $3.5");
}
else if(w<=3)
{
System.out.println("运输成本为: $5.5");
}
else if(w<=10)
{
System.out.println("运输成本为: $8.5");
}
else if(w<=20)
{
System.out.println("运输成本为: $10.5");
}
else
{
System.out.println("The package cannot be shipped");
}
}
}
第十九题
package b18;
import java.util.Scanner;
/**
* 孤鸿
* 题目:求三角形周长
* 2024/1/29 09:09
*/
public class exer19 {
public static void main(String[] args) {
double girth=0.0;
//输入三条有效的边长
Scanner input=new Scanner(System.in);
double[] arr=new double[3];
System.out.println("请输入三条边的长度");
boolean flag=false;
while(true) {
for (int i = 0; i < 3; i++) {
System.out.print("请输入第"+(i+1)+"条边的长度:");
double a= input.nextDouble();
if (a<= 0) {
flag = true;
break;
} else {
arr[i] = a;
flag = false;
continue;
}
}
break;
}
//判断三条边能否组成三角形
if((arr[0]+arr[1]>arr[2])&&(arr[0]+arr[2]>arr[1])&&(arr[1]+arr[2]>arr[0]))
{
for (int i = 0; i < arr.length; i++) {
girth+=arr[i];
}
System.out.println("周长是:"+girth);
}
else {
System.out.println("输入的三条边不能组成三角形");
}
}
}
第二十题
package b18;
import java.util.Scanner;
/**
* 孤鸿
* 题目:风冷温度计算公式
* Twc=35.74+0.6215Ta-35.75V0.16+0.4275TaV0.16
* Ta 室外温度华氏摄氏度 V 表示速度 以每小时英里数为单位 Twc 是风冷温度
* 2024/1/29 09:45
*/
public class exer20 {
public static void main(String[] args) {
System.out.println("请输入温度值和风速值!");
System.out.println("温度华氏摄氏度:");
Scanner input=new Scanner(System.in);
double Ta=input.nextDouble();
if(Ta<-58||Ta>41){
System.out.println("输入无效值!");
return;
}
System.out.println("风速:");
double V=input.nextDouble();
if(V<2){
System.out.println("输入无效值!");
return;
}
else{
System.out.println("风冷温度为:"+(35.74+0.6215*Ta-35.75*Math.pow(V,0.16)+0.4275*Ta*Math.pow(V,0.16)));
}
}
}
第二十一题
package b18;
import java.util.Scanner;
/**
* 孤鸿
* 题目:
* 2024/1/29 09:59
*/
public class exer21 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter year(eg .2012):");
int year=input.nextInt();
System.out.print("Enter the month (1-12):");
int month=input.nextInt();
System.out.print("Enter the day of the month (1-31):");
int q=input.nextInt();
//判断输入的当月天数是否合法.
switch (month) {
case 2 -> {
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
if (q > 29) {
System.out.println(year+"年2月没有"+q+"天");
return;
} else if (q > 28) {
System.out.println(year+"年2月没有"+q+"天");
return;
}
}
}
case 1, 3, 5, 7, 8, 10, 12 -> {
if (q > 31) {
System.out.println(year+"年"+month+"月没有"+q+"天");
return;
}
}
case 4, 6, 9, 11 -> {
if (q > 30) {
System.out.println(year+"年"+month+"月没有"+q+"天");
return;
}
}
default -> {
}
}
//如果月份是一月和二月 进行转换
if(month==1||month==2){
month+=12;
year-=1;
}
int h=(q+(26*(month+1))/10+(year%100)+(year%100)/4+(year/100)/4+5*(year/100))%7;
switch (h) {
case 0 -> System.out.println("Day of the week is Saturday");
case 1 -> System.out.println("Day of the week is Sunday");
case 2 -> System.out.println("Day of the week is Monday");
case 3 -> System.out.println("Day of the week is Tuesday");
case 4 -> System.out.println("Day of the week is Wednesday");
case 5 -> System.out.println("Day of the week is Thursday");
case 6 -> System.out.println("Day of the week is Friday");
default -> {
}
}
}
}
第二十二题
package b18;
import java.util.Scanner;
/**
* 孤鸿
* 题目:
* 2024/1/29 12:43
*/
public class exer22 {
public static void main(String[] args) {
System.out.println("请输入一个坐标轴!");
Scanner input=new Scanner(System.in);
System.out.print("Enter a point with two coordinates :");
double x=input.nextDouble();
double y=input.nextDouble();
if(Math.pow(Math.pow((x-0),2)+Math.pow((y-0),2),0.5)<=10){
System.out.println("Point ("+x+" , "+y+" ) is in the circle");
}
else {
System.out.println("Point ("+x+" , "+y+" ) is not in the circle");
}
}
}
第二十三题
package b18;
import java.util.Scanner;
/**
* 孤鸿
* 题目:
* 2024/1/29 13:00
*/
public class exer23 {
public static void main(String[] args) {
System.out.println("请输入一个坐标轴!");
Scanner input=new Scanner(System.in);
System.out.print("Enter a point with two coordinates :");
double x=input.nextDouble();
double y=input.nextDouble();
if(Math.abs(x)<=5&&Math.abs(y)<=2.5){
System.out.println("Point ("+x+" , "+y+" ) is in the rectangle");
}
else {
System.out.println("Point ("+x+" , "+y+" ) is not in the rectangle");
}
}
}
第二十四题
package b18;
/**
* 孤鸿
* 题目:
* 2024/1/29 13:07
*/
public class exer24 {
public static void main(String[] args) {
String [] arrpoint=new String[13];
String [] arrsuit=new String[]{"Clubs","Diamonds","Hearts","Spades"};
//写入牌的大小
for (int i = 0; i < arrpoint.length; i++) {
if(i==0){
arrpoint[i]="Ace";
}
else if(i==10){
arrpoint[i]="Jack";
}
else if(i==11){
arrpoint[i]="Queen";
}
else if(i==12)
{
arrpoint[i]="King";
}
else {
arrpoint[i]=String.valueOf(i+1);
}
}
String[][] result=new String[arrsuit.length][arrpoint.length];
for (int i = 0; i < result.length; i++) {
for (int j = 0; j < result[i].length; j++) {
result[i][j]=arrsuit[i]+" of "+arrpoint[j];
}
}
//开始随机抽牌
int i=(int)(Math.random()*4);
int j=(int)(Math.random()*13);
System.out.println("The card you picked is "+result[i][j]);
}
}
第二十五题
package b18;
import java.util.Scanner;
/**
* 孤鸿
* 题目:
* 2024/1/29 13:32
*/
public class exer25 {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.print("Enter x1,y1,x2,y2,x3,y3,x4,y4:");
double x1=input.nextDouble();
double y1=input.nextDouble();
double x2=input.nextDouble();
double y2=input.nextDouble();
double x3=input.nextDouble();
double y3=input.nextDouble();
double x4=input.nextDouble();
double y4=input.nextDouble();
if(((y1-y2)*(x4-x3)-(x2-x1)*(y3-y4))!=0) {
double x=(((y1-y2)*x1-(x1-x2)*y1)*(x4-x3)-(x2-x1)*((y3-y4)*x3-(x3-x4)*y3))/((y1-y2)*(x4-x3)-(x2-x1)*(y3-y4));
double y=((y1-y2)*((y3-y4)*x3-(x3-x4)*y3)-((y1-y2)*x1-(x1-x2)*y1)*(y3-y4))/((y1-y2)*(x4-x3)-(x2-x1)*(y3-y4));
System.out.println("The intersecting point is at (" + x+","+ y + ")");
}
else {
System.out.println("The two lines are parallel.");
}
}
}
第二十六题
package b18;
import java.util.Scanner;
/**
* 孤鸿
* 题目:
* 2024/1/29 14:03
*/
public class exer26 {
public static void main(String[] args) {
System.out.println("Enter an integer:");
Scanner input=new Scanner(System.in);
int num=input.nextInt();
System.out.print("Is "+num+" divisible by 5 and 6 ? ");
if(num%5==0&&num%6==0)
{
System.out.println("True");
}
else {
System.out.println("False");
}
System.out.print("Is "+num+" divisible by 5 or 6 ? ");
if(num%5==0||num%6==0)
{
System.out.println("True");
}
else {
System.out.println("False");
}
System.out.print("Is "+num+" divisible by 5 or 6 ,but not both ? ");
if((num%5==0||num%6==0)&&(!(num%5==0&&num%6==0)))
{
System.out.println("True");
}
else {
System.out.println("False");
}
}
}