Home | Community | Message Board


This site includes paid links. Please support our sponsors.


Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

Myyco.com Shop: Golden Teacher Liquid Culture For Sale

Jump to first unread post Pages: 1
Can someone help me with my Java assignment
    #13114969 -

The assignment is to write a program that computes the volume of a cylinder. It should read in a radius and length and compute the volume using the following formulas:

Area = radius * radius * Pi
Volume = area * length
------------------------------------------------------------------------
the pic below shows what I have so far. when i run it, it allows me to enter the radius and length numbers but then gives me a bunch of errors when it tries to compute it. :mushroom2:






here's what the errors say:


Enter the Radius: 5
Enter the Length: 4
Your Area is: Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at CJH02_02.main(CJH02_02.java:34)


help is appreciated:mushroom2::mushroom2::mushroom2::mushroom2::mushroom2:

Extras: Filter Print Post Top
Re: Can someone help me with my Java assignment [Re: subiedude]
    #13115060 -

I would use string builder to build the strings, instead of the print formatters first...i think the problem with those is though you should use %f instead of %d...however, i would try:

Code:

StringBuilder sb = new StringBuilder();

sb.append("Your area is: ");
sb.append(area);

if( sb.length() > 0 )
{
System.out.println(sb.toString());
sb.delete(0,sb.length());
}

sb.append("Your volume is: ");
sb.append(volume);

if(sb.length() > 0)
{
System.out.println(sb.toString());
sb.delete(0,sb.length());
}


Edited by supra (08/28/10 04:14 PM)

Extras: Filter Print Post Top
Jump to top Pages: 1

Myyco.com Shop: Golden Teacher Liquid Culture For Sale


Similar ThreadsPosterViewsRepliesLast post
* Learning Java
( 1 2 all )
shroominliketruman 1,338 21 09/14/10 11:35 PM
by citricacidx
* super simple java help needed please mayfly 985 11 01/23/08 01:02 PM
by Annom
* Anyone here know java?
( 1 2 3 all )
Psy Baba 3,471 40 05/04/07 11:29 PM
by AgingHippy
* Starting to program java wiggles 1,091 4 04/01/07 09:20 PM
by Seuss
* whats a good programming language after java/c(++)?
( 1 2 3 all )
smoothrider267 3,288 47 07/23/09 10:47 AM
by gilesypopper
* java problems Idiot 2,119 14 04/25/06 06:39 PM
by Idiot
* Java Problems gregorio 922 8 11/30/08 10:41 PM
by Learyfan
* Java 6.0 YthanA 409 1 12/12/06 12:21 PM
by Seuss

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: trendal, automan, Northerner
451 topic views. 0 members, 1 guests and 3 web crawlers are browsing this forum.
[ Show Images Only | Sort by Score | Print Topic ]
Search this thread:

Copyright 1997-2026 Mind Media. Some rights reserved.

Generated in 0.024 seconds spending 0.007 seconds on 16 queries.