[Solved] How to get a remainder in java


From your comment, it looks like you just need help with who will be left without a car. You need to use modular division (some people call it remainder) with the percent sign (%). Here is the line of code you are missing:

System.out.println("Amount of people without a car: "+students%sum);

The full code for the program is:

import java.util.Scanner;
public class Solution {
    public static void main(String[] args) [
        Scanner s=new Scanner(System.in);
        int carCapacity=5;

        System.out.println("How many students?");
        int students=s.nextInt();
        int cars=students/carCapacity;
        int leftOver=students%carCapacity;

        System.out.println("Cars needed: "+cars);
        System.out.println("Students left over: "+leftOver);


    }
}

2

solved How to get a remainder in java