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 5 of 5

Thread: Help wi this

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help wi this

    Anybody know how to write this program

    Write a program that asks the user to enter a positive integer, n, and compute the following sum:
    20 + 22 + 23 + ... + 2n


    Hint: use the following to workout the power:

    import java.math.;
    ab = Math.pow(a,b)
    math.pow(a,b) returns double type

  2. #2
    Member
    Join Date
    Dec 2012
    Posts
    33
    My Mood
    Confused
    Thanks
    2
    Thanked 2 Times in 1 Post

    Default Re: Help wi this

    no one is going to do your homework for you, try, then post the code and tell us where are you stuck

  3. #3
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help wi this

    Quote Originally Posted by moucho View Post
    Anybody know how to write this program...
    I know how to do this!

  4. #4
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help wi this

    Quote Originally Posted by curmudgeon View Post
    I know how to do this!
    this is wat ive done but i dont know if its the right program the question
    import java.util.Scanner;
    public class Maths1{
     
    	public static void main( String[] args)
    	{
    		Scanner input = new Scanner (System.in);
     
    		System.out.println("Enter a number, then enter" +" your power function number.");
    			byte a, b;
     
     
    		a = input.nextByte();
            b = input.nextByte();
            a = (byte) Math.pow(a, b);
     
     
    			System.out.print(a);
     
     
     
    		}
     
    }
    Last edited by Norm; December 28th, 2012 at 12:38 PM. Reason: added code tags

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help wi this

    Before you can write any code you need to understand what the code needs to do.
    Can you take a value for n and manually work out what the result should be?
    Show the steps you took and what the results are.
    If you don't understand my answer, don't ignore it, ask a question.