Results 1 to 4 of 4
Thread: Whats missing in this code?
- 02-13-2013, 09:12 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
Whats missing in this code?
Hi all,
Im new to JAVA and i seem to have figured out to make the correct code for calculating the area of a rectangle.
However something goes terribly wrong when i want to continue and code to calculate for the perimeter as well.
Im just totally stuck and dont know how to proceed. Ive tried a lot of things but just get errors. Please help.
This is my code so far.
import java.util.Scanner;
public class TriangleArea {
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
double base = 0;
double height = 0;
System.out.print("Enter the base: ");
base = sc.nextInt();
System.out.print("Enter the height");
height = sc.nextInt();
double area = base * height;
System.out.print("Area of rectangle is : "+ area);
--------------------------------------------------------------------> (until here everything is fine... now the next line is getting me into trouble when i want to calculate the perimeter. How shall i proceed? Please no rude comments. Im trying my hardest to learn and Im very new to this and need all the help i can get.
System.out.print ("Enter the base and height") ;
double perimeter = 2 * (base + height);
System.out.print("Perimeter of square is: " + perimeter)
Kind regards
- 02-13-2013, 11:00 PM #2
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
Re: Whats missing in this code?
Hi Patricia,
Can you please explain what errors you are getting.
I've not looked hard at the code and just ran it to see what it does and have noticed two issues.
Firstly, you missed the semicolon off your last print statement. Secondly, the scanner is attempting to read in an int when you are assigning it to a double. I suspect you mean for this to be a decimal value so you will need to change the method called.
Regards.
- 02-14-2013, 09:21 AM #3
Re: Whats missing in this code?
Patricia6946, please go through the Forum Rules, particularly the third paragraph. Also go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.
To change the subject line, click 'Edit Post' and then 'Go Advanced'
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-14-2013, 09:36 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Whats wrong with my jsp code?
By ur2cdanger in forum JavaServer Pages (JSP) and JSTLReplies: 5Last Post: 10-28-2011, 04:16 AM -
whats wrong with my code
By naved in forum New To JavaReplies: 5Last Post: 07-15-2011, 02:06 AM -
Whats wrong with my code
By zit1343 in forum New To JavaReplies: 9Last Post: 01-24-2011, 01:06 AM -
whats wrong with my code?
By beandip408 in forum New To JavaReplies: 6Last Post: 11-03-2010, 12:01 AM -
Whats with my code??
By RSYR in forum New To JavaReplies: 6Last Post: 11-05-2009, 12:04 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks