Ask your own question, for FREE!
Computer Science 25 Online
OpenStudy (pottersheep):

Guidance please !! Write a method to calculates exponents. Pass 2 values: the number and the exponent it is to be calculated to; return the result. Display the returned value

OpenStudy (pottersheep):

This is what I did (fail)

OpenStudy (pottersheep):

import java.util.Scanner; public class exponentmethod { public static void main (String args []){ Scanner input = new Scanner (System.in); int total = 0 , first = 0 , second = 0 ; System.out.print("Enter base"); first= input.nextInt(); System.out.print("Enter exponent"); second= input.nextInt(); total= a(first, second); System.out.print("result"+total); } static int result=1; static int a(int t,int y){ return result; int ctr=1; while (ctr!=y){ result = result * t; ++ctr; } } }

OpenStudy (pottersheep):

can I use a loop in my method ? please help........

OpenStudy (pottersheep):

i think my return part is wrong but idk how to do it

OpenStudy (anonymous):

please format your code and put it to pastebin.com or codepad.org or somewhere else

OpenStudy (anonymous):

http://pastebin.com/n2uTQdib as i commented about spaces near = it's not essential but it's good practise and you will follow java coding conventions

OpenStudy (pottersheep):

Ok here it is http://pastebin.com/AMiaBFDR

OpenStudy (anonymous):

well you didn't change it at all

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!