AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Positive and Negative integer counter

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Fri Sep 29, 2006 7:11 am    Post subject: Positive and Negative integer counter Reply with quote



Hello everyone,

I am working on a program that needs to read an unspecified number of
integers and determine how many positive and negative values there are.
Also, the program needs to end when the input is 0 (zero). Here is the
code I have which is causing me problems!!! I would greatly appreciate
all of the help!

import java.util.Scanner;
public class Counter
{

public static void main(String[] args)
{
int inputNumber;
int count;
int number;

Scanner keyboard = new Scanner(System.in);
count = 0;
number = 0;

System.out.print("Enter your first integer: ");
inputNumber = keyboard.nextInt();

while (inputNumber >0);
{
count++;
System.out.print("Enter your next integer, or 0 to
end: ");
inputNumber = keyboard.nextInt();
}

while (inputNumber <0);
{
number++;
System.out.print("Enter your integer, or 0 to end:");
inputNumber = keyboard.nextInt();
}

if (count == 0)
{
System.out.print("You didn't enter any data!");
}
else
{
keyboard.nextInt();
System.out.print("You entered " + count + " positive
integers.");
System.out.print("You entered " + number + " negative
integers.");
}

}

}

Thanks again.

--John
Back to top
No Name
Guest





PostPosted: Fri Sep 29, 2006 7:11 am    Post subject: Re: Positive and Negative integer counter Reply with quote



StaR.BoY2005 (AT) gmail (DOT) com wrote:
Quote:
I am working on a program that needs to read an unspecified number of
integers and determine how many positive and negative values there are.
Also, the program needs to end when the input is 0 (zero). Here is the
code I have which is causing me problems!!! I would greatly appreciate
all of the help!

Take your homework, shove it and piss off.
Back to top
Tobias Schröer
Guest





PostPosted: Fri Sep 29, 2006 12:16 pm    Post subject: Re: Positive and Negative integer counter Reply with quote



Hi,

as this seems to be homework, I won't give you the answer, jsut a few hints.

StaR.BoY2005 (AT) gmail (DOT) com schrieb:
Quote:
Hello everyone,

import java.util.Scanner;
public class Counter
{

public static void main(String[] args)
{
int inputNumber;
int count;
int number;

Scanner keyboard = new Scanner(System.in);
count = 0;
number = 0;

System.out.print("Enter your first integer: ");
inputNumber = keyboard.nextInt();


Look at the next steps from here: what does the used statements do?
Remember the specifications: read an int _until_ it is zero, else
increase either the positive or the negative integer counter.


Quote:
while (inputNumber >0);
{
count++;
System.out.print("Enter your next integer, or 0 to
end: ");
inputNumber = keyboard.nextInt();
}

while (inputNumber <0);
{
number++;
System.out.print("Enter your integer, or 0 to end:");
inputNumber = keyboard.nextInt();
}

Now the result output...

Quote:

if (count == 0)
{
System.out.print("You didn't enter any data!");
}
else
{
keyboard.nextInt();
^^^^^^^^^^^^^^^^^^^

why this?

Quote:
System.out.print("You entered " + count + " positive
integers.");
System.out.print("You entered " + number + " negative
integers.");
}

}

}

Thanks again.

--John


Tobi
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.