# Positive and Negative Integers

Page 1 of 1

## 1 Replies - 17891 Views - Last Post: 02 April 2009 - 11:09 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=96916&amp;s=16ccbd630475574a7e50fe34242ad449&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 almayhm

Reputation: 0
• Posts: 7
• Joined: 24-March 09

# Positive and Negative Integers

Posted 02 April 2009 - 11:05 AM

Hey guys, I've written another program for my studies and im stumped once again. Im trying to set up a program that reads positive and negative integers from the keyboard and seperates them into 2 list, Positive, and Negative. I got it to do that, but it prints after each number is read. I would like it to wait until the user has finished inputing all numbers, and then seperate them into thier appropriate list. Thanks in advanced guys!

//Allan Rodriguez

import java.util.Scanner;

public class posneg
{
public static void main(String[] args)
{
int x;
int e=0;

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter a Positive or Negative Integer or 'e' to end: ");
x = keyboard.nextInt();

while (x != e)
{

System.out.print("Enter a Positive or Negative Integer or 'e' to end: ");
x = keyboard.nextInt();
}

if (x>0)
{
System.out.println("These Are Positive: " + x);

}

if (x<0)
{

System.out.println("These Are Negative: " + x);
}

}

}

Is This A Good Question/Topic? 0

## Replies To: Positive and Negative Integers

### #2 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

## Re: Positive and Negative Integers

Posted 02 April 2009 - 11:09 AM

you can use arrays or an ArrayList for this, create one for the positive ints and one for the negative ints and after the user finished inputting the numbers, then print them out