loops and other problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arishma
    New Member
    • Sep 2007
    • 4

    #1

    loops and other problems

    someone pliz help have written this program but it does not display 2 to that power instead it asks to enter a power and when -1 is entered the program ends m missing out on something if someone could help then

    import java.io.*;
    class power
    {
    public static void main(String[] args)throws IOException
    {
    int count = 0;
    int power;
    int exponent = 2;
    double result = 1;

    BufferedReader Keyboard=new BufferedReader( new
    InputStreamRead er(System.in));

    power = Integer.parseIn t(Keyboard.read Line());

    while (count < exponent)
    {
    result = result * 2;
    count = count +1;
    }



    }

    }
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by arishma
    someone pliz help have written this program but it does not display 2 to that power instead it asks to enter a power and when -1 is entered the program ends m missing out on something if someone could help then
    [code=java]
    import java.io.*;
    class power
    {
    public static void main(String[] args)throws IOException
    {
    int count = 0;
    int power;
    int exponent = 2;
    double result = 1;

    BufferedReader Keyboard=new BufferedReader( new
    InputStreamRead er(System.in));

    power = Integer.parseIn t(Keyboard.read Line());

    while (count < exponent)
    {
    result = result * 2;
    count = count +1;
    }



    }

    }[/code]

    Use a suitable Thread Title and use Code Tags while you do Post according to Reply Guidelines.
    use exit(0) or break statement from a loop.
    Good luck.

    Kind regards,
    Dmjpro.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by arishma
      someone pliz help have written this program but it does not display 2 to that power instead it asks to enter a power and when -1 is entered the program ends m missing out on something if someone could help then

      [code=java]
      import java.io.*;
      class power
      {
      public static void main(String[] args)throws IOException
      {
      int count = 0;
      int power;
      int exponent = 2;
      double result = 1;

      BufferedReader Keyboard=new BufferedReader( new
      InputStreamRead er(System.in));

      power = Integer.parseIn t(Keyboard.read Line());

      while (count < exponent)
      {
      result = result * 2;
      count = count +1;
      }



      }

      }[/code]
      I edited your thread title. About your problem: you don't print anything after that
      while loop so you can't know what exactly happened. Without actually thinking
      about your problem I can see that none of the code actually does something with
      variable 'power', i.e. it could've been left out altogether.

      kind regards,

      Jos

      Comment

      Working...