Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

input of value integer problem.

Thread view: 
Jeremy - 09 Feb 2007 00:33 GMT
> Hey, Sorry to bother you, I have output that is not doign what i want it
> to
> do.   I'm just having trouble getting it to run the way I want it to do.
> I'm
> having trouble  getting the first value read specific the number of value
> to
> input from the users....
> here's the output of the program i got.
> Indicate how many values you want to input:2
>
> Indicate numbers you want to calcuate for smallest integer:2
> Press any key to continue...
>
> import java.util.Scanner;
> public class Input// public class name input
>
> {
> public static void main (String args[])// main method to begine xecution
> of
> program
> {
> Scanner input = new Scanner(System.in);
> int counter=1;// counter intialized to 1
> int smallestnumber=0;//smallest number intialized to 0;
> int values=0;// values intialized to 0;
> int number=0; number is intialized to 0;
>
> {
> System.out.printf("Indicate how many values you want to input:"); // ask
> user
> how many values you want to input and prompts you to do that.
> values =input.nextInt();
>
> while ( counter<=values)// while statement that will count within values
> {
> System.out.println();
> ++counter;
> values=number;
>
> }
>
> System.out.printf("Indicate numbers you want to calcuate for smallest
> integer:");// ask  what number you want to calcuate for the smallest
> integer.
> number =input.nextInt();
> while (values==number)// this is not right statement anything
> {
> number=smallestnumber;
> if (smallestnumber<=number)
> {
>
> System.out.println(smallestnumber);
> }
> }
>
> }
> }
}
Hendrik Maryns - 12 Feb 2007 19:56 GMT
Jeremy schreef:
>> Hey, Sorry to bother you, I have output that is not doign what i want it
>> to
[quoted text clipped - 8 lines]
>> Indicate numbers you want to calcuate for smallest integer:2
>> Press any key to continue...

You didn’t formulate a question, but I’ll give some comments on your code:

>> import java.util.Scanner;
>> public class Input// public class name input
[quoted text clipped - 22 lines]
>> values=number;
>> }

Since number is 0, values will be 0 after the first loop, which makes
this code equivalent to:

if (values >= 1) {
 System.out.println();
 counter = 2;
 values = 0;
}

That doesn’t seem to make any sense.  Please reconsider.

>> System.out.printf("Indicate numbers you want to calcuate for smallest
>> integer:");// ask  what number you want to calcuate for the smallest
>> integer.
>> number =input.nextInt();
>> while (values==number)// this is not right statement anything

values is 0, so it will only execute when the user entered 0.

>> {
>> number=smallestnumber;
[quoted text clipped - 4 lines]
>> }
>> }

Have a look at the last link in my sig.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.