Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SumOfNumbers {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int last = 5;
- int start = 1;
- int current = 0;
- System.out.println("Final: "+ sumOfAll(start, last, current));
- }
- public static int sumOfAll(int start, int last, int current)
- {
- int total = current;
- if (start <= last)
- {
- total += start;
- start++;
- sumOfAll(start, last, total);
- System.out.println(total);
- }
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement