0

Hey guys, i'm fairly new here. Just stuck on a program. It seems like it should be right, based on my pseudo code, but something went wrong. Edit: without using Math.pow; Edit: kind of not looking for the answer, just what i did wrong,, other wise, i wont know it for the test.

/**
 * @(#)powerRangers.java
 *
 *
 * @*EDITED MY NAME*
 * @version 1.00 2010/10/8
 */

import java.util.Scanner;
public class powerRangers
{

    /**
     * Creates a new instance of <code>powerRangers</code>.
     */
    public powerRangers()
    {
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
{

    	int value, counter = 0, total, icounter;
    	Scanner scan = new Scanner (System.in);
        // ASK FOR VALUE
        System.out.println("Enter the value");
        value = scan.nextInt();
        icounter = (value - 1);


        while (icounter <= value)
        {
        	total = (2^icounter);
        	System.out.println ("2 to the power: " + counter +" is: " + total);
			counter ++;
        	icounter --;
        }
}
}

Edited by AnAnonymousUser: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ChaseRLewis
0

Look up what the carrot ^ operator does. To do powers without the math class, consider using a for loop that multiples 2 a certain amount of times.

0

^ does not do exponents it is a boolean gate function.

What you are probably looking for are shift operators << ,>>, >>> read about those and you should see what to do.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.