1 Replies - 11590 Views - Last Post: 02 April 2009 - 11:09 AM Rate Topic: -----

#1 almayhm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1