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 !!b/mIEkVC6+3Cvk1 2011-12-29 17:35

>>157
no... I am most doubtful of your demoting comment. I am quite good at mathematics thank you.
>>155
I think we went over this already so im not going to reiterate it for you.

Because this came up a few times...:

public class someClass{
    static int count = 0;
    static boolean neg = false;
    static int v = 1;
    public static void main(String[] args){
        System.out.println(powerUp((int) Integer.parseInt(args[0]),(int)Integer.parseInt(args[1])) + "");
        }
    public static double powerUp(int x, int n){
        count = 0;
        neg = false;
        if(n < 0){
            n = -1 *n;
            neg = true;
            }
        for(;count < n; count++){
            v = v * x;
            }
        if(neg){
            return (1/(double)v);
            }
        return v;
        }
    }

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