Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions ch_06/Exercise06_03.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ public static void main(String[] args) {
}
}

public static int reverse(int number) {
String temp = "";
while (number > 0) {
int t = number % 10;
number /= 10;
temp += t;

}
return Integer.parseInt(temp);
public static int reverse(int n) {
int num1 = 0;
while( n != 0){
num1 =num1 *10;
num1 += n % 10 ;
n = n / 10;
}
return num1;
}

public static boolean isPalindrome(int number) {
Expand All @@ -44,4 +43,4 @@ public static boolean isPalindrome(int number) {
return n1.equals(n2);

}
}
}
21 changes: 13 additions & 8 deletions ch_06/Exercise06_05.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ public class Exercise06_05 {
public static void displaySortedNumbers(double num1, double num2, double num3) {
double temp;

if (num1 > num2) {
if( num1 < num2 ){
temp = num1;
num1 = num2;
num2 = temp ;
}
if(num1 < num3){
temp = num1 ;
num1 = num3;
num3 = temp;
}
if( num2 < num3){
temp = num2;
num2 = num1;
num1 = temp;
} else if (num2 > num3) {
temp = num3;
num3 = num2;
num2 = temp;

num2 = num3;
num3 = temp;
}
System.out.println(num1 + " " + num2 + " " + num3);
}
Expand Down