Could anyone tell where is the error in the program? There is a compile-time error... When I hit compile it shows error in the 40th line saying that 'r' might not have been initialised.. I can't get that.. Pease could anybody help??

import java.util.Scanner;
public class Customer_Account
{
  public static void main(String args[])
  {
      Scanner in= new Scanner(System.in);
      int dep, n, money=0;
      int r;
      System.out.println("Enter the amount deposited");
      dep= in.nextInt();
      System.out.println("Enter the number of years");
      n= in.nextInt();
      if(dep<2000 && n>=2)
      {
          r=5;
          money=(dep*r*n)/100;
      }
      if(dep>=2000 && dep<6000 && n>=2)
      {
          r=7;
          money=(dep*r*n)/100;
      }
      if(dep>6000 && n>=1)
      {
          r=8;
          money=(dep*r*n)/100;
      }
      if(n>=5)
      {
          r=10;
          money=(dep*r*n)/100;
      }
      if((dep<2000 && n>=2)&&(dep>=2000)&&(dep<6000 && n>=2)&&(dep>6000 && n>=1)&&(n>=5))
      {
          r=3;
          money=(dep*r*n)/100;
      }
      System.out.println("Money deposited= Rs."+ dep);
      System.out.println("Time Period="+" " +n+"years");
      System.out.println("Rate Of Interest="+ r + "%");
      System.out.println("Amount In Account= Rs."+ money);
    }

It would be great if I get the help before monday the 26th coz my computer exam is on that day..So obviously I need it before that!!!
Thanks, Ordella.

Recommended Answers

All 7 Replies

So change "int r;" to:
int r = 0;

Assign r a value and make the compiler happy. The compiler wants you to assign initial values to local variables (inside methods)

Thank you so so so so much for pointing out such a silly mistake of mine!!!!
And finally NormR1 my compiler is extremely happy now.. Thank You so much!!!
Regards, Ordella :)

As I mentioned in an earlier post of mine that I have my computer exam on th 26th March 2012.. So I was just wondering if anyone could provide me with some programming questions for my school level which I could practice on my own.
If anyone is posting me practice questions then I request do not forget that am just in class Tenth.. Please do not give something whish is sbove my level.
Thanks, Ordella

Well, there are pleny of open questions on DaniWeb.
If you attempt to answer them, you could practice your "chops".
It really depends on the scope of the questions, too.

You might find some easy enough problems in Rosetta code You can do your own solution and see the previous Java answer, and compare them.

Thank You Sir pyTony. I will make it a point to try these.
Regards, Ordella

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.