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: Java Program Loop Possibly needed

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Program Loop Possibly needed

    I have to make a table that takes two integers called int a and int b suppose int a is 5 and int b is 1 then I have to add, subtract,divide, get the remainder and then taking the first number to the power of the second number without using a Java library method like pow. The input values should be seperated by a single tab
    character, as should the output value If I first add these numbers I will get 6 then subtract to give 4 multiply to give 5 and divide to give 5 then take the remainder to get 0 and
    then take the power of the first number to the power of the second number to get 5.

    Here is how the table should look
    5 1 6 4 5 5 0 5


    I have started doing the code and it does fine but the problem is I do not know how to take the first number to the power of the second number and display it in the table
    without using a Java Library method like pow

    Here is what I did so far for the display part of this program it is almost complete just the last part
    System.out.println(a + "\t" + b + "\t" + (a+b) + "\t" + (a-b) + "\t" + (a*b) + "\t" + (a/b)+ "\t" + (a%b));

    I need a loop to be made to display the first number to the power of the second number and then take a result and display it in the sop code. If anyone knows how to do it please show how this loop should look and take that result to the sop code.

    Thank You everyone for the help


  2. #2
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Java Program Loop Possibly needed

    dear mike
    you can create ur own power function and call it after taking input.


    int power(int a,int b)
    {
    // write your code for power calculation
    }


    System.out.println("a^b"+power(a,b));
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

Similar Threads

  1. Need a program using only for loop its urgent
    By pokuri in forum Object Oriented Programming
    Replies: 2
    Last Post: January 14th, 2011, 05:13 AM
  2. Possibly a noobish issue
    By FitzGerald in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 16th, 2010, 12:57 PM
  3. Imitating a JFrame extended program with JPanel; help needed...
    By emigrant in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 15th, 2010, 02:30 PM
  4. array program assistance needed
    By JavaNoob82 in forum Collections and Generics
    Replies: 4
    Last Post: December 14th, 2009, 05:49 AM
  5. Array program help needed
    By SCM in forum Loops & Control Statements
    Replies: 2
    Last Post: December 2nd, 2009, 11:28 PM