# Help With Arrays/Math in Java

fenderguy440
Offline
Joined: 2011-03-22

Now, on to the project. Remember the grain of rice story? The raja gave out 1 grain of rice on the first day and doubled every day for 30 days. Well, we are going to change the story a bit.
§ Your program will ask the user how many grains of rice they get on the first day.
o Note: rice will double every day just like before.
§ Your program will then ask the user for how many days they get rice.

I have two problems with this project
1) I don't know how to use exponents in Java. I believe my equation is mathematically correct but the answer is not coming out correctly
2) I dont know how to use arrays entirely so I cant print out the number of rice I Will be getting on all days.
here is the equation:

java.util.Scanner;
class myown{
public static void main(String args[]){
Scanner Andrew = new Scanner(System.in);
System.out.println("Enter how many pieces of rice you begin with: ");
rice = Andrew.nextInt();
System.out.println("Enter how many days you will receive rice for: ");
days = Andrew.nextInt();
``    public static void main(String[] args)     {        Scanner s = new Scanner( System.in );        System.out.print( "Enter no of Rice: " );        int ans1 = s.nextInt();                System.out.print( "Enter no of Days: " );        int ans2 = s.nextInt();        int rice = ans1;                for( int nLoop = 0; nLoop < ans2; nLoop++ )        {            System.out.printf( "On day %d, he gets %d rice\n", nLoop + 1, rice );            rice = rice * 2;        }    }``