All pastes #755995 Raw Edit

Miscellany

public text v1 · immutable
#755995 ·published 2007-10-31 01:47 UTC
rendered paste body
/*
 * Main.java
 *
 * Created on October 30, 2007, 12:24 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package homework4;

/**
 *
 * @author pimp daddy
 */

import java.util.Scanner;
import java.util.*;
import java.lang.String;
import java.text.*;
import java.lang.System;
import java.lang.*;

public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
public static void main(String[] args) {  
            String optionS;
            char option;
            
            do{
                                    
            Scanner scan = new Scanner(System.in);
            System.out.println("\nPlease select from the following options:"
                                + "\n\t 1. Print Default Diamond Shape"
                                + "\n\t 2. Calculate Fibonacci Numbers"
                                + "\n\t 3. Divide Numbers"
                                + "\n\t 4. Custom Diamond Shape");
            System.out.println("Enter your selection: ");
            optionS = scan.next();
            option = optionS.charAt(0);
            
            switch(option) {
                  
            case('1'): 
                printshape();
                break;
            case('2'):
                fibo();
                break;
//the other cases here so i can test 1 by 1
                default:
                    System.out.println("Sorry! Dimitri says you can't use that command!!");
                
            }//end switch
            
        } while(option!='q');
        
    }//end main method
        public static void printshape()
           {
        System.out.println("");
        System.out.println("    *\n   ***\n  *****\n *******\n  *****\n   ***\n    *"); // Q.E.D.
          }
        public static int fibo()
         {
        Scanner scan = new Scanner(System.in);
        System.out.println("");
        System.out.println("Please enter an integer: ");
        int n = scan.nextInt();
	// Base Case:
	//   If k <= 2 then fib(k) = 1.
	if (n <= 2) {
	    return 1;
	}
	// Recursive Case:
	//   If k > 2 then fib(k) = fib(k-1) + fib(k-2).
	else {
	    return fibo(n-1) + fibo(n-2);
	} 
     }//end fibo
     public static void printdiamond(){
        Scanner scan = new Scanner(System.in);
        int n = 3;
        int q = n/2;
        for(int a = -q;a <= q;a++) {
        int b = (a < 0)?-a:a;
        int c = q-b;
        for(int d = 0;d <= q+c;d++) {
        System.out.print((d < b)?" ":"*");
        }
        System.out.println();
    }
     }//end diamond
}//end main