Untitled

 avatar
unknown
plain_text
2 years ago
1.2 kB
4
Indexable
import java.io.*;
import java.util.*;

public class NumberStack {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(new File("numbers.txt"));
        double a = 5.0; // replace with your desired value
        double b = 10.0; // replace with your desired value
        
        Stack<Double> lessThanA = new Stack<>();
        Stack<Double> betweenAB = new Stack<>();
        Stack<Double> greaterThanB = new Stack<>();
        
        while (sc.hasNextDouble()) {
            double number = sc.nextDouble();
            if (number < a) {
                lessThanA.push(number);
            } else if (number >= a && number <= b) {
                betweenAB.push(number);
            } else {
                greaterThanB.push(number);
            }
        }
        
        while (!lessThanA.empty()) {
            System.out.println(lessThanA.pop());
        }
        while (!betweenAB.empty()) {
            System.out.println(betweenAB.pop());
        }
        while (!greaterThanB.empty()) {
            System.out.println(greaterThanB.pop());
        }
        
        sc.close();
    }
}
Editor is loading...