# Thread: how do i make the integer limited to 10

1. Member
Join Date
Sep 2011
Posts
69
Rep Power
0

## how do i make the integer limited to 10

my code allows you to enter integers but unlimited how can i restrict it to only ten

Java Code:
```import java.util.*;
public class SumPositiveNegative
{

public static void main(String [] args)
{
//initialise variables
int counter=0; //used to count number of inputs by operator
int numbers;//the number keyed in by operator
int sumAll=0; //total of all numbers keyed in
int sumPos=0; //total positive number keyed in
int sumNeg=0; //total negative numbers keyed in
//initialise input display
Scanner keyIn = new Scanner (System.in);

//start of input code display on output
System.out.println("Enter 10 integers: ");
//while what is keyed in is less than 10 do this
while(counter<10){
numbers = keyIn.nextInt();//next number
counter++; //counter increased by 1
sumAll = sumAll + numbers; // add the number keyed in to sumAll

if(numbers > 0) //if positive number keyd in do this
sumPos = sumPos + numbers;//add the number keyed in to sumPos
else //if negative, <0, do this
sumNeg = sumNeg + numbers;//add the number keyed in to sumNeg
}

//output total: positive, negative and sum
System.out.println("Sum of the positive numbers: " + sumPos);
System.out.println("Sum of the negative numbers: " + sumNeg);
System.out.println("Sum of all the numbers: " + sumAll);
}
}```
many Thanks Andy.

2. ## Re: how do i make the integer limited to 10

It seems like you know what you have to do (in involves an if statement or a do/while loop of some kind, or just capping the value), but you're looking for a way around it. There's no way around it.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•