Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Cummulative Sum prob.. need some help!

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cummulative Sum prob.. need some help!

    Hey Everyone,
    I need some help with cummulative sum, without using math class methods.

    Heres the question

    Write a method named pow that accepts integers for a base A and an exponent B and computes and returns A^B.

    This is what i got so far..
    //This is problem #3 on cum. sums.
    public class Powwow {
    	public static void main(String[] args) {
          prod = 1; 	
    		for(int i = 1; i <= 1; i++);
          	System.out.println("prod = prod * a");
         }
    }
    Btw how do i put my code in the "red" box?

    Thanks
    Last edited by helloworld922; October 21st, 2009 at 03:15 PM.


  2. #2
    Junior Member
    Join Date
    Oct 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Cummulative Sum prob.. need some help!

    the first problem with your code is you did not declare the variable prod, this would give you an error while compiling.you are also telling the computer to print out "prod = prod * a" as a string so you would not see any results even if your code was functioning.

    first off you need to write a method named pow. a method is a section of code that can be used inside your class. for example, you have a main() method. pow will need two parameters A,and B.

    for example
     
    public static void main(String args[]){
     
    }
    public static int pow(int A,int B){    //make sure to specify the return type, in this case an integer
     
    //Code goes here
     
    }

    after making the method just use it in main. you can use a variable to hold the returned value or just print it directly to the screen.
    public static void main(String args[]){
           int num=pow(5,6);
           System.out.println(num);
           //or 
           System.out.println(pow(4,5));   //4^5 printed on a new line
    }
    Last edited by Flamespewer; October 21st, 2009 at 06:55 PM.