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

Thread: help me , im confused!!!!

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    7
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help me , im confused!!!!

    import java.util.Scanner;
    public class Eiks
    {
    public static void main (String args [])
    {
    Scanner scan = new Scanner (System.in);
    int base, exponent;
    int ans;
    System.out.println("Enter your base:");
    base = scan.nextInt();
    System.out.print("Enter your exponent:");
    exponent = scan.nextInt();

    prod = base ^ exponent;
    System.out.print("the prod is : " + prod);
    }
    }


    * for example base = 2 , exponent = 3 the ans is 8 (2*2*2)
    my program is running but the operation is wrong , the prog giving me a wrong ans. .

    please help. .


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

    Default Re: help me , im confused!!!!

    Okay, here is the problem, the '^' operator in java is NOT how you do an exponent. It is actually XOR, a binary math function. Instead of "prod = base ^ exponent;", use "prod = Math.pow(base, exponent);"

    Hope that helps!

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    7
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help me , im confused!!!!

    Quote Originally Posted by wrightm96 View Post
    Hope that helps!
    thanks it really helps . iLy lol

Similar Threads

  1. Confused..
    By jadowers in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 5th, 2011, 12:56 PM
  2. [SOLVED] confused
    By joon in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 12th, 2011, 11:40 AM
  3. I'm confused...
    By acolar in forum Object Oriented Programming
    Replies: 1
    Last Post: April 14th, 2011, 12:14 PM
  4. Ayudame! :confused:
    By wasaki in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 22nd, 2010, 10:37 AM
  5. Confusion with C/C++
    By Eric in forum Java Applets
    Replies: 0
    Last Post: December 22nd, 2008, 02:18 PM