Skip to content

Instantly share code, notes, and snippets.

@pepet96
Created November 13, 2013 23:41
Show Gist options
  • Save pepet96/7458569 to your computer and use it in GitHub Desktop.
Save pepet96/7458569 to your computer and use it in GitHub Desktop.
ClassifyNumbers
import java.util.Scanner;
class ClassifyNumbers {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int initial, low, high, sum, value, i;
System.out.println("How many numbers do you wish to analyze?");
initial = input.nextInt();
i = 1;
sum = 0;
System.out.println("which is the lowest integer that I should consider?");
low = input.nextInt();
System.out.println("which is the highest integer that I should consider?");
high = input.nextInt();
for (i = 1; i <= initial; i++){
System.out.println("Type a number: ");
value = input.nextInt();
if (value <= low) {
System.out.println("This number is out of range");
sum = sum;
}
else if (value >= high) {
System.out.println("This number is out of range");
sum = sum;
}
else if (value >= low) {
System.out.println("This number within range");
sum = sum + value;
}
}
System.out.println("The sum is: " + sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment