How do I collect 4 variables of different types (string, float and integer) of input on a single line like this: (string, float, float, int)?
For example:
"joey" 17.4 39.9 6
This is what my code looks like now. It works but it only collects the variables one line at a time.
import java.util.Scanner;
public class EmployeePay{
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String employeeID = "";
double hrsWorked;
double wageRate;
int deductions;
System.out.println("Hello Employee! Please input your employee ID, hours worked per week, hourly rate, and deductions: ");
employeeID = keyboard.nextLine();
hrsWorked = keyboard.nextFloat();
wageRate = keyboard.nextFloat();
deductions = keyboard.nextInt();
}
}
Do I need to use a for loop?
keyboard.nextLine();is your problem. The rest are collected one line at a time only if you hit enter, you can collect them on one line.6and that it's not636?