473,657 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why wont my program work?

1 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.JOptionPane;
  3.  
  4. import java.util.*;
  5. public class Assignment1
  6.  
  7. {
  8. // do nothing constructor
  9. public Assignment1()
  10. {}
  11. public static void main(String[]args)
  12. {
  13. Assignment1 assign = new Assignment1();
  14. assign.Runit();
  15. }
  16. private void Runit()
  17.     {
  18.  
  19.           //Gather the information from the user
  20.        Scanner input1 = new Scanner(System.in);
  21.        String gender = JOptionPane.showInputDialog("Gender: ");
  22.        Scanner input2 = new Scanner(System.in);
  23.        int age;
  24.        JOptionPane.showInputDialog("enter age: ");
  25.        age = input2.nextInt();
  26.  
  27.        JOptionPane.showInputDialog(age);
  28.  
  29.         if (age <= 17 )
  30.             System.out.println( "Person is a boy");
  31.         else  
  32.             System.out.println ( "Person is a Man");
  33.     }
  34.  
  35.  
  36. }
  37.  
  38.  
  39.  
Jun 14 '09 #1
1 1700
Nepomuk
3,112 Recognized Expert Specialist
Well first of all, because you're mixing command line input (Scanners for System.in) and input via Swing objects (InputDialogs). And secondly because you're not doing anything with the age you read in line 24. Have a good look at the lines 20 to 27 and think about what exactly they do.

Greetings,
Nepomuk
Jun 14 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
8013
by: Catherine | last post by:
I am having a problem viewing asp pages on iis version 5.1 xp pro. HTML pages are viewable on http://localhost but .asp pages are not. I have created a test program called timetest.asp with the following code: <html> <head> <title>Test ASP</title>
7
4463
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns System_String. I don't see a difference in the previous code and what I have now. Can anyone find where I went wrong? Thanks a bunch! //Open new stream reader and writer to read in file //And write to a new file. StreamWriter swa=new...
3
2942
by: me | last post by:
Is there any particular reason why a requiredfieldvalidator cant validate a listbox? I have bound the two together but the validator always returns false on isvalid and so does the Page, no matter if the user selects an item in the listbox or not.
5
2465
by: Mr Newbie | last post by:
Debug.Assert( False, "Why wont I display ??") I am trying to use this in my code but it wont display. The app is running on my local machine and the above code under a button click event. What am I missing ? Cheers mr N . . .
2
1619
by: ff2 | last post by:
Ok i'm using Borland CBX and Windows XP. My program is to convert farenheit to celsius. I got the code off the CD that came with "Sams Teach Yourself C++ in 24 Hours" so i doubt the code is wrong. I can run it fine in the IDE but i can run the .exe in Windows XP but when i type in the temperature, say 120 and then press enter it closes the window(it opens by default in the commandline) I know that its not the program because I have tried...
0
979
by: slughead | last post by:
people! im new here, please be nice... im having problem with the setup package in my recent project! need help please... i have created setup package to distribute the my software, however, when i started running the setup package program to other machine for distribution, it halts and asks for "...the system not updated reboot to update..." etc or something like that.... so what i did is install the vb application in that machine run...
4
21716
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a webserver to see if service A needs to be updated. What service B does if it sees their is an update for service A is to download a new copy of the service A executable, stop service A, replace the executable with the new copy, and start service B...
3
6270
Frinavale
by: Frinavale | last post by:
Hi there, I am currently behind a firewall that wont let me send emails. As a result my smtpClient.send(emailMessage) wont work on my IIS but this method does work through the VisualStudio development/test environment. Lately I've been testing the cases where my site encounters a fault to make sure everything is handled nicely. My only concern is that the smtpClient.send() is taking way to long to time out. I've already tried to...
2
2584
by: jcollins1991 | last post by:
im trying to make a program thats supposed to check whether 2 strings are anagrams of each other (anagram = same letters in both strings, but in different orders... "cool as wet art" , and "cs at waterloo" for example). while (str2.get_Length() != 0) //<---- checks whether second string is "cleared" { //loop, from start of string (k = 0) to end of string (length2) for (k = 0; k <=...
1
2815
by: WestyCHC | last post by:
Morning all from a newbie. I have recently written an automation program (my first ever program) for testing and now I am trying to read XML data and assign the values to variables (rather than Excel). Using XPathNavigator I managed to read some of the data, but in order to do this I had to manually remove the attributes from the Parent Nodes. Going forward this isnt an option as we may be reading and running hundreds of files a day and so I...
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.