Novicane All American 15416 Posts user info edit post |
import javax.swing.*; import java.text.*;
class AllFives { public static void main (String [] args) { double a; double cg; a = JOptionPane.showInputDialog(null, "Please enter the value of A"); cg = (Math.pow(a, 0.5e1) + 0.5e1) / a / 0.5e1; JOptionPane.showMessageDialog(null, "A = " + cg); } }
I get a incompatible type error. Obviously it's something im not declaring right. any help?9/13/2005 10:06:38 AM |
jdlongNCSU All American 7105 Posts user info edit post |
showInputDialog returns a string, not a double... 9/13/2005 10:12:12 AM |
Novicane All American 15416 Posts user info edit post |
forgot to parse 9/13/2005 10:14:41 AM |
Novicane All American 15416 Posts user info edit post |
another question:
/* Converts seconds into minutes, hours, days */
import javax.swing.*; import java.text.*;
public class SecondsConvert {
public static void main (String [] args) {
String secondsStr; int seconds, minutes, hours; System.out.println( "This program converts a total number of seconds "); System.out.println( "into the equivalent minutes and seconds. ");
secondsStr = JOptionPane.showInputDialog(null, "Enter the seconds: "); seconds = Integer.parseInt(secondsStr); minutes = seconds / 60; seconds = seconds % 60; System.out.println(); System.out.println(seconds + " seconds = " ); System.out.println( minutes + " minutes, and " + seconds + " seconds. "); } }
// 1. For which range of input values does the existing program work as expected?
Obviously, it doesnt like decimals. I tried adding the DecimalFormat method but that doesn't like integers.9/13/2005 11:06:30 AM |
jdlongNCSU All American 7105 Posts user info edit post |
so whats the question? the one in comments?
sounds like a homework question to me... 9/13/2005 11:10:51 AM |
Novicane All American 15416 Posts user info edit post |
Well it's a lab and the teacher isn't here, so I have no way of contacting him and we don't have a TA.
anyway
Yeah ignore that comment. The question is how can I correct incorrect ranges, which im assuming a incorrect range is a decimal # because the program errors up. I tried using the DecimalFormat to ("0") but that only likes doubles.
I don't need an answer, just a direction to be looking in and i'll figure it out. 9/13/2005 11:14:45 AM |
jdlongNCSU All American 7105 Posts user info edit post |
well, I think the only hint I can give you is to look at the variable type... is a number with a decimal an integer?
[Edited on September 13, 2005 at 11:25 AM. Reason : nevermind that last piece...] 9/13/2005 11:23:41 AM |