# Java Problem

Page 1 of 1

## 4 Replies - 1007 Views - Last Post: 01 September 2009 - 06:05 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=123242&amp;s=d22c2745af4915c5f17d61354d2c4836&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 handa

Reputation: 0
• Posts: 1
• Joined: 01-September 09

# Java Problem

Posted 01 September 2009 - 01:03 AM

Ques1 Program takes two double numbers amount(A) and interest®and an integer number years(n) and prints out all input and amount earned after 5 years .the amount earned in a year is calculated by An+1 = An*R .If an entered number is less than 0 display "invalid input".

This is not working properly

[code]
import java.util.*;

public class amount
{
public static void main(String[] args)

{
Scanner keyboard = new Scanner(System.in);
//get a number and assign it to variable
System.out.println("Pls enter Principal : ");
int A1 = keyboard.nextInt();
System.out.println("Pls enter Rate of interest charged : ");
int R1 = keyboard.nextInt();
int N = 5;

if (A1>0)
{
int A1 = A1+1* int R1;

{System.out.println("Amount = "+ A1);

}
Else if (A1<0)
{
{System.out.println("Invalid Input");

}

}

}

}

Is This A Good Question/Topic? 0

## Replies To: Java Problem

### #2 Travis1012

Reputation: 36
• Posts: 226
• Joined: 05-August 09

## Re: Java Problem

Posted 01 September 2009 - 01:38 AM

handa, on 1 Sep, 2009 - 05:03 PM, said:

Ques1 Program takes two double numbers amount(A) and interest®and an integer number years(n) and prints out all input and amount earned after 5 years .the amount earned in a year is calculated by An+1 = An*R .If an entered number is less than 0 display "invalid input".

This is not working properly

```import java.util.*;

public class amount
{
public static void main(String[] args)

{
Scanner keyboard = new Scanner(System.in);
//get a number and assign it to variable
System.out.println("Pls enter Principal : ");
int A1 = keyboard.nextInt();
System.out.println("Pls enter Rate of interest charged : ");
int R1 = keyboard.nextInt();
int N  = 5;

if  (A1>0)
{
int A1 = A1+1* int R1;

{System.out.println("Amount = "+ A1);

}
Else if (A1<0)
{
{System.out.println("Invalid Input");

}

}

}

}

```

First thing first no need to redeclare A1 or R1 as int it just creates errors.

Also if you want double numbers, A1 and R1 should be declared as double.

Else is actually else. Java is a case sensitive language.

```import java.util.*;

public class amount
{
public static void main(String[] args)

{
Scanner keyboard = new Scanner(System.in);
//get a number and assign it to variable
System.out.println("Pls enter Principal : ");
double A1 = keyboard.nextDouble();
System.out.println("Pls enter Rate of interest charged : ");
double R1 = keyboard.nextDouble();
double N  = 5;

if  (A1>0)
{
A1 = A1 + 1 * R1;

System.out.println("Amount = "+ A1);

}
else if (A1<0)
{
System.out.println("Invalid Input");

}

}

}

```

This post has been edited by Travis1012: 01 September 2009 - 01:53 AM

### #3 NeoTifa

• NeoTifa Codebreaker, the Scourge of Devtester

Reputation: 4187
• Posts: 18,393
• Joined: 24-September 08

## Re: Java Problem

Posted 01 September 2009 - 08:29 AM

It would help if you posted the errors you are getting. I dunno if Travis solved all your problems or not, but please be a little more descriptive of your errors in the future.

### #4 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

## Re: Java Problem

Posted 01 September 2009 - 06:03 PM

NeoTifa, on 1 Sep, 2009 - 07:29 AM, said:

It would help if you posted the errors you are getting. I dunno if Travis solved all your problems or not, but please be a little more descriptive of your errors in the future.

And please, Handa, respect rule #5 of this forum
"Java Help" is kind of a useless topic title in a forum dedicated to help people with problem in Java

P.S. why have I always to be the one writing this ?

### #5 Locke

• Sarcasm Extraordinaire!

Reputation: 550
• Posts: 5,624
• Joined: 20-March 08

## Re: Java Problem

Posted 01 September 2009 - 06:05 PM

pbl, on 1 Sep, 2009 - 07:03 PM, said:

"Java Help" is kind of a useless topic title in a forum dedicated to help people with problem in Java

P.S. why have I always to be the one writing this ?

Well, first of all, that's wrong. In this particular thread...it's Java Problem.

And, I dunno why you're the only one that writes those.