What's new
DroidForums.net | Android Forum & News

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Java help

ilikemoneygreen

Silver Member
What am I doing wrong? i cant seem to get the second dialog box to popup to enter the value. I could get it to work just in the command prompt using System.out.print but its not working out with the dialog box.
Code:
/**Area of rectangle *//* ilikemoneygreen
 * CIS163 29843
 * August 24, 2012
 */
 import java.util.Scanner; // scanner package
 import javax.swing.JOptionPane;
 public class RectangleArea {
     public static void main(String[] args) {
         //input the length and width
         Scanner input = new Scanner(System.in);


         //prompt user for length
         JOptionPane.showInputDialog(null, "Enter the length : " , "Length" , JOptionPane.INFORMATION_MESSAGE);
         double length = input.nextDouble();
         //Prompt user for Width
         JOptionPane.showInputDialog(null, "Enter the width : " , "Width" , JOptionPane.INFORMATION_MESSAGE);
         double width = input.nextDouble();


         //calculate area
         double area = length * width;
         //Display the results
         System.out.println("The area of a Rectangle with a width of " + width + " and a length of " + length + " is " + area); 
     }
 }
If you help me, ill give you a cyber hug. :hail:
 
Im having flashbacks to middle school and programming my TI81...not the 83, not the 83+, not the silver edition...the 81. Unfortunately Im not quite sure where you are going wrong...The code looks good to me but Im by no means a java guy. Is it giving you any output at all?
 
lol, i cant say ive ever seen an 81. sounds like you had fun with it though. My friend was obsessed with his calc, he played doom in class i think then the teacher wiped it all away. :biggrin:
and the out i get is it does the first dialog box. I then input a number and hit enter then nothing happens, it hangs. Im thinking its a logic error, which are usually a pain.....
 
I learned early on to archive my apps...that way when they wipe, the app stays. Great for having cheat sheets :cool-b: In any case, sorry...Im drawing a blank. This is the reason I hate coding. I hope someone else can be of assistance here.
 
Back
Top