79107258

Date: 2024-10-20 14:13:31
Score: 1.5
Natty:
Report link

Do you need to solve the problem of finding the middle of the list in one pass when the number of elements is unknown in advance?

public static void main(String[] args) {

    var in = "0 1 2 3 4";
    var scan = new Scanner(in);
    var midAddress = -1;

    while(scan.hasNext()) {
        midAddress++;
        scan.next();
        if (!scan.hasNext()) break;
        scan.next();
    }

    System.out.println("Middle address: " + midAddress);
}
Reasons:
  • Has code block (-0.5):
  • Ends in question mark (2):
Posted by: Konstantin Makarov