0

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.

Edited by Ezzaral: Code formatting.

4
Contributors
7
Replies
8
Views
4 Years
Discussion Span
Last Post by Ordella
Featured Replies
1

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

Edited by thines01: code formatting

1

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

0

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 :)

0

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

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.