This week's giveaway is in the Spring forum.
We're giving away four copies of Microservices Testing (Live Project) and have Chris Love & Andres Sacco on-line!
See this thread for details.
Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

won't let me input integer values

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ppl. i am new to java. i am using JCreato (Version 3.10.009). thing is when i run this program it wont prompt me to enter the integer values.

can anyone of you tell me why.

import java.io.*;

class max_of_two_numbers
{
public static void main(String args[])
{
int a;
int b;

try
{
System.out.println("Enter an integer: ");
a = Integer.parseInt(args[0]);
System.out.println("Enter an integer: ");
b = Integer.parseInt(args[0]);

if(a > b)
{
System.out.println(a + " is the biggest.");
}
else
{
System.out.println(b + " is the biggest.");
}

}catch(Exception e)
{
System.out.println("Error");
}
}
}
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no code there to read the values from the command prompt.

Please follow the link below to get an understanding of how to prompt the user to enter values from command prompt.

http://www.devdaily.com/java/edu/pj/pj010005/pj010005.shtml

Hope that helps.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I faced the same problem using JCreator, I guess that you cannot use the command line with JCreator.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way you've wrote this, the numbers a and b must be entered like arguments of the main methode when you're running your program

ex. java max_of_two_numbers 6 7 (only if you use a command prompt to run your program), where 6 is a and 7 is b

If you really want to be prompted to enter the numbers and read them from the ketboard, you should read that thing posted by Rahul

By the way, I suggest to you to switch to blueJ - www.bluej.org which is much more easier to use for a beginner
 
Garry Meax
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot guys.

i have managed to do it but it is quite long. is there a short way for this.

import java.io.*;

class max_of_two_num
{
public static void main(String args[])
{
DataInputStream a=new DataInputStream(System.in);
DataInputStream b=new DataInputStream(System.in);

String as=new String();
String bs=new String();

try
{
System.out.print("Enter an integer: ");
as=a.readLine();
System.out.print("Enter an integer: ");
bs=b.readLine();
}catch(Exception e)
{
}

int x=Integer.valueOf(as);
int y=Integer.valueOf(bs);

if(x > y)
{
System.out.println(x + " is the biggest.");
}
else
{
System.out.println(y + " is the biggest.");
}
}
}
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Garry, please [url=http://faq.javaranch.com/view?UseCodeTags]add code tags[/code] to your post. You can edit your post using the icon at the top right of it. Thanks!

And welcome to the Ranch!
[ February 12, 2005: Message edited by: Ilja Preuss ]
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Garry Meax:
thanks a lot guys.

i have managed to do it but it is quite long. is there a short way for this.



Long ??? That program is tiny... you should would not worry about how long ( or how many lines) your program has at this point. It easier to debug this way and you can clearly see the logic behind your own code ( readability )...
but here is a "short" version of your program


have fun...
reply
    Bookmark Topic Watch Topic
  • New Topic