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
This is what I did (fail)
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; } } }
can I use a loop in my method ? please help........
i think my return part is wrong but idk how to do it
please format your code and put it to pastebin.com or codepad.org or somewhere else
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
well you didn't change it at all
Join our real-time social learning platform and learn together with your friends!