Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Latest commit

 

History

History
History
47 lines (43 loc) · 1.5 KB

File metadata and controls

47 lines (43 loc) · 1.5 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import java.util.Scanner;
public class FourDigitInteger {
public boolean isOdd(int number) {
return !(number % 2 == 0);
}
public boolean isPalindrome(int number) {
String string = Integer.toString(number);
if ((string.substring(0, 1).equals(string.substring(3, 4))) && (string.substring(1, 2).equals(string.substring(2, 3)))) {
return true;
} else {
return false;
}
}
public boolean isPerfectSquare(int number) {
int i;
for (i = 32; i < 100; i++) { // originally put 31
if ((i * i) == number) return true;
}
return false;
}
public static void main(String[] args) {
System.out.println("Enter a number to check if it is odd: ");
Scanner keyboard = new Scanner(System.in);
int number = keyboard.nextInt();
keyboard.close();
FourDigitInteger test = new FourDigitInteger();
if (test.isOdd(number)) {
System.out.println("The number is odd.");
} else {
System.out.println("The number is not odd.");
}
if (test.isPalindrome(number)) {
System.out.println("The number is a palindrome.");
} else {
System.out.println("The number is not a palindrome.");
}
if (test.isPerfectSquare(number)) {
System.out.println("The number is a perfect square.");
} else {
System.out.println("The number is not a perfect square.");
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.