-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
331 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package uah; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Factorial { | ||
public static void main(String[] args) { | ||
System.out.print("Enter an integer: "); | ||
Scanner in = new Scanner(System.in); | ||
int num = in.nextInt(); | ||
Factorial fact = new Factorial(); | ||
try { | ||
System.out.println(fact.compute(num)); | ||
} catch (Exception e) { | ||
System.out.print(e.toString()); | ||
} | ||
} | ||
|
||
public int compute(int i) { | ||
int result = 0; | ||
if (i==0) | ||
result = 1; | ||
else | ||
result = i*compute(i-1); | ||
return result; | ||
} | ||
|
||
/* Initial version after the first JUnit */ | ||
/* public int compute(int i) { | ||
return 1; | ||
}*/ | ||
|
||
/* After adding second, third, etc. JUnit */ | ||
/* public int compute(int i) { | ||
int result = 0; | ||
if (i==0 || i ==1) | ||
result = 1; | ||
else | ||
if (i==2) | ||
result = 2; | ||
else | ||
if (i==3) | ||
result = 6; | ||
else | ||
result = i*compute(i-1); | ||
return result; | ||
}*/ | ||
|
||
/*After refactoring */ | ||
/* public int compute(int i) { | ||
int result = 0; | ||
if (i == 0 || i == 1) result = 1; | ||
else result = i * compute(i - 1); | ||
return result; | ||
}*/ | ||
|
||
/* public int compute(int i) { | ||
if (i<0) | ||
throw new IllegalArgumentException("No negatives: " + i); | ||
int result = 0; | ||
if (i==0 || i ==1) | ||
result = 1; | ||
else | ||
if (i==2) | ||
result = 2; | ||
else | ||
if (i==3) | ||
result = 6; | ||
else | ||
result = i*compute(i-1); | ||
return result; | ||
}*/ | ||
|
||
/* | ||
public int compute(int i) { | ||
if (i<0) | ||
throw new IllegalArgumentException("No negatives: " + i); | ||
int result = 0; | ||
if (i == 0 || i == 1) result = 1; | ||
else result = i * compute(i - 1); | ||
return result; | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.