Skip to content

Commit c6694fc

Browse files
Simplifying boolean returns (#3796)
* Simplifying boolean returns * add comment back
1 parent fb09eb2 commit c6694fc

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

src/main/java/com/thealgorithms/maths/DudeneyNumber.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ public static boolean isDudeney(int n) {
3333
}
3434

3535
//If the cube root of the number is not equal to the sum of its digits we return false.
36-
if (cube_root != sum_of_digits) {
37-
return false;
38-
}
39-
40-
return true;
36+
return cube_root == sum_of_digits;
4137
}
4238
}

src/main/java/com/thealgorithms/sorts/LinkListSort.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ public static boolean isSorted(int p[], int option) {
4444
Arrays.sort(b);
4545
// array b is sorted and it will return true when checked with sorted list
4646
LinkListSort uu = new LinkListSort();
47-
if (uu.compare(a, b)) {
48-
return true;
49-
} else {
50-
return false;
51-
}
47+
return uu.compare(a, b);
5248
// The given array and the expected array is checked if both are same then true
5349
// is displayed else false is displayed
5450
case 2:
@@ -73,11 +69,7 @@ public static boolean isSorted(int p[], int option) {
7369
}
7470
LinkListSort uu1 = new LinkListSort();
7571
// array b is not sorted and it will return false when checked with sorted list
76-
if (uu1.compare(a, b)) {
77-
return true;
78-
} else {
79-
return false;
80-
}
72+
return uu1.compare(a, b);
8173
// The given array and the expected array is checked if both are same then true
8274
// is displayed else false is displayed
8375
case 3:
@@ -103,11 +95,7 @@ public static boolean isSorted(int p[], int option) {
10395
Arrays.sort(b);
10496
// array b is sorted and it will return true when checked with sorted list
10597
LinkListSort uu2 = new LinkListSort();
106-
if (uu2.compare(a, b)) {
107-
return true;
108-
} else {
109-
return false;
110-
}
98+
return uu2.compare(a, b);
11199
// The given array and the expected array is checked if both are same then true
112100
// is displayed else false is displayed
113101
default:

src/main/java/com/thealgorithms/strings/Anagrams.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ boolean approach1(String s, String t) {
5656
Arrays.sort(
5757
d
5858
);/* In this approach the strings are stored in the character arrays and both the arrays are sorted. After that both the arrays are compared for checking anangram */
59-
if (Arrays.equals(c, d)) {
60-
return true;
61-
} else {
62-
return false;
63-
}
59+
60+
return Arrays.equals(c, d);
6461
}
6562
}
6663

0 commit comments

Comments
 (0)