Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

NEED URGENT HELP

Name: edo-chan 2011-12-28 11:11

sup /prog/

Ive asked this everywer already but peopl seem too lame to make even a simple program like so i hope the mighty anon programers of 4chan are more skilled

what im trying to do is to Write a method taking two parameters x and n that computes the nth power of x without using ^ or declaring a new variable inside the method or using Math lib.
and it has to be coded in JAVA (i know it sux but dont ask why i use dat shit)
hep plox!

Name: IisMathwizard 2011-12-29 14:18

**Quick edit to allow for entering of zero and negatives
// @Author: IisMathwizard

public class someClass{
    static int count = 0;//OP Said not within the method so
    static boolean neg = false; // global
    public static void main(){
        System.out.println(powerUp(10,12) + "");
        }
    public static double powerUp(int x, int n){
        count = 0;
        neg = false;
        if(n == 0){
            return 1;
        }
        if(n < 0){
            n = -1 *n;
            neg = true;
            }
        for(;count < n-1; count ++){
            x*=x;
            }
        if(neg){
            return (1/(double)x);
            }
        return x;
        }
    }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List