Results 1 to 5 of 5
-
17th Jul 2011, 09:10 AM #1OPMember
[java] Output a Two Decimal Value
I wanted display the result with two decimal values? (12.50) but it seems to be displaying 0 instead of 12.50.
Code:import java.io.*; public class InputOutput { public static void main(String[] args) { String base=""; String height=""; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("Input base value = "); base = input.readLine(); System.out.print("Input height value = "); height = input.readLine(); } catch(IOException e) { System.out.print("Error"); } int area = 1/2*(Integer.parseInt(base)* Integer.parseInt(height)); System.out.println("The Area of the right triangle is "+ area); } }
Hillside Reviewed by Hillside on . [java] Output a Two Decimal Value I wanted display the result with two decimal values? (12.50) but it seems to be displaying 0 instead of 12.50. import java.io.*; public class InputOutput { public static void main(String args) { String base=""; String height=""; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); Rating: 5
-
17th Jul 2011, 09:16 AM #2Member
Change area type to float
float area = 1/2*(Integer.parseInt(base)+ Integer.parseInt(height));
-
17th Jul 2011, 09:21 AM #3OPMember
^The output was:
Code:The Area of the right triangle is 0.0
-
17th Jul 2011, 10:04 AM #4Member
make the following changes
Code:import java.io.*; public class InputOutput { public static void main(String[] args) { double base=0; double height=0; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("Input base value = "); base = Double.parseDouble(input.readLine()); System.out.print("Input height value = "); height = Double.parseDouble(input.readLine()); } catch(IOException e) { System.out.print("Error"); } double area = 0.5*(base* height); System.out.println("The Area of the right triangle is "+ area); } }
-
22nd Jul 2011, 12:11 AM #5Member
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Java stinks: Turn off your Java browser plugin
By Loget in forum General DiscussionReplies: 37Last Post: 5th Sep 2012, 07:40 AM -
How To Fix Validation Output: 70 Errors
By BigBang24 in forum Webmaster DiscussionReplies: 7Last Post: 31st Mar 2011, 08:49 AM -
Is there a php function to convert text to decimal ncr?
By Tigger in forum Webmaster DiscussionReplies: 0Last Post: 20th Jan 2011, 07:48 AM -
How do I disable output buffering in php?
By jamilv in forum Server ManagementReplies: 9Last Post: 18th Dec 2010, 11:12 PM -
[php] Compression | Output Buffer control
By litewarez in forum Web Development AreaReplies: 2Last Post: 7th Jul 2010, 06:14 PM
themaLeecher - leech and manage...
Version 5.03 released. Open older version (or...