-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckIfSame.java
More file actions
76 lines (67 loc) · 2.45 KB
/
CheckIfSame.java
File metadata and controls
76 lines (67 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.Scanner;
public class CheckIfSame
{
public static void main( String[] args )
{
Scanner input = new Scanner(System.in);
//Prompt the user for two integers
System.out.println("Please enter a number: ");
int num1 = input.nextInt();
System.out.println("Please enter a second number: ");
int num2 = input.nextInt();
/*
1.Write a program named CheckIfSame.java2.
Prompt the user for two integers.
The program should determine whether the two integers
have the same quotient when divided by 10, and if they are divisible by 10
a.If the two integers have the same quotient, print “Quotients are the same!”
b.If they are both evenly divisible by 10, print “Both divisible by ten!”
*/
if(num1 / 10 == num2 / 10)
{
System.out.println("Quotients are the same!");
if(num1 % 10 == 0 && num2 % 10 == 0)
{
System.out.println("Both divisible by ten!");
}
/*
3.If the two integers are both divisible by 10 and have the same quotient,
check whether the quotient is divisible by 2.
If they are, print “Quotients are divisible by two!”,
if not print “Quotients are not divisible by two!”
*/
if((num1 / 10 == num2 / 10) && (num1 % 10 == 0 && num2 % 10 == 0))
{
if(num1 % 2 == num2 % 2)
{
System.out.println("Quotients are divisible by two!");
}
else
{
System.out.println("Quotients are not divisible by two");
}
}
}
/*
4.If the two integers are not divisible by 10,
check if the two integers have the same remainder when divided by 10.
If they do, print “Remainders are the same!”
*/
else if((num1 % 10 != 0) && (num2 % 10 != 0))
{
if(num1 % 10 == num2 % 10)
{
System.out.println("Remainders are the same!");
}
}
/*
5.If they do not have the same quotient, are not divisible by 10,
and do not have the same remainder when divided by 10,
print “Nothing is the same!”
*/
if((num1 / 10 != num2 / 10) && (num1 % 10 != 0 && num2 % 10 != 0) && (num1 % 10 != num2 % 10))
{
System.out.println("Nothing is the same!");
}
}
}