Simplifying boolean returns (#3796)

* Simplifying boolean returns

* add comment back
This commit is contained in:
Nathan Cheshire 2022-12-17 21:03:09 -06:00 committed by GitHub
parent fb09eb289e
commit c6694fc1bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 25 deletions

View File

@ -33,10 +33,6 @@ public class DudeneyNumber {
}
//If the cube root of the number is not equal to the sum of its digits we return false.
if (cube_root != sum_of_digits) {
return false;
}
return true;
return cube_root == sum_of_digits;
}
}

View File

@ -44,11 +44,7 @@ public class LinkListSort {
Arrays.sort(b);
// array b is sorted and it will return true when checked with sorted list
LinkListSort uu = new LinkListSort();
if (uu.compare(a, b)) {
return true;
} else {
return false;
}
return uu.compare(a, b);
// The given array and the expected array is checked if both are same then true
// is displayed else false is displayed
case 2:
@ -73,11 +69,7 @@ public class LinkListSort {
}
LinkListSort uu1 = new LinkListSort();
// array b is not sorted and it will return false when checked with sorted list
if (uu1.compare(a, b)) {
return true;
} else {
return false;
}
return uu1.compare(a, b);
// The given array and the expected array is checked if both are same then true
// is displayed else false is displayed
case 3:
@ -103,11 +95,7 @@ public class LinkListSort {
Arrays.sort(b);
// array b is sorted and it will return true when checked with sorted list
LinkListSort uu2 = new LinkListSort();
if (uu2.compare(a, b)) {
return true;
} else {
return false;
}
return uu2.compare(a, b);
// The given array and the expected array is checked if both are same then true
// is displayed else false is displayed
default:

View File

@ -56,11 +56,8 @@ public class Anagrams {
Arrays.sort(
d
);/* 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 */
if (Arrays.equals(c, d)) {
return true;
} else {
return false;
}
return Arrays.equals(c, d);
}
}