John Delmark Aguilar
Would you like to react to this message? Create an account in a few clicks or log in to continue.
John Delmark Aguilar

Personal Forum
 
HomeSearchLatest imagesRegisterLog in

 

 Recursion Java (Factoring + Triangle)

Go down 
AuthorMessage
dElmARk
Admin
Admin
dElmARk


Posts : 92
Join date : 09/04/2012

Recursion Java (Factoring + Triangle) Empty
PostSubject: Recursion Java (Factoring + Triangle)   Recursion Java (Factoring + Triangle) Icon_minitimeTue Oct 23, 2012 8:13 pm

Recursion Java (Factoring + Triangle)

Code:


import java.util.*;
class Recursion{
    public static void main(String []args){
    Scanner ss = new Scanner(System.in);
    System.out.print("Type \"1\" for Factorial or type \"2\" for Triangle ");
    int ch = ss.nextInt();
        if(ch == 1){
        System.out.print("Enter a number to find its Factorial: ");
        int a = ss.nextInt();
        int fact = 1;
            for (int i= 1; i<=a; i++){
            System.out.println(fact + " times " + i + " = " + fact*i);
            fact=fact*i;
            }
            System.out.println("The Factor of "+a+" is "+ +fact);
        }
        else if(ch == 2){
        System.out.print("Enter a base number to to get the sum of the elements of the Triangle: ");     
        int j = ss.nextInt();
        int a = 1;
            for (int i= 1; i<=j; i++){
            a=i*(i+1)/2;
            System.out.println(a);
            }
        System.out.println("The sum of the elements of the triangle is " + a);
     
        }else{
        System.out.println("Invalid Input! \nProgram Exit");
        }
    }
}

Back to top Go down
https://delmark.forumtl.com
 
Recursion Java (Factoring + Triangle)
Back to top 
Page 1 of 1
 Similar topics
-
» Payroll Java
» Java Comments
» Java Programming Index
» Compiling Java Program
» List Of Java Keywords

Permissions in this forum:You cannot reply to topics in this forum
John Delmark Aguilar :: dElmARk Productions :: Java Programs :: Tutorials-
Jump to: