Java Problem

Program takes two double numbers amount(A) and interest(R)and an inte

Page 1 of 1

4 Replies - 625 Views - Last Post: 01 September 2009 - 06:05 PM Rate Topic: -----

#1 handa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 36
  • View blog
  • Posts: 222
  • Joined: 05-August 09

Re: Java Problem

Posted 01 September 2009 - 01:38 AM

View Posthanda, 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");



}


}

}




Posted Image

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

Was This Post Helpful? 0
  • +
  • -

#3 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2670
  • View blog
  • Posts: 15,713
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

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

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java Problem

Posted 01 September 2009 - 06:03 PM

View PostNeoTifa, 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 ?
Was This Post Helpful? 0
  • +
  • -

#5 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Java Problem

Posted 01 September 2009 - 06:05 PM

View Postpbl, 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. :lol:

And, I dunno why you're the only one that writes those.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1