Я пытаюсь сохранить кучу переменных через буферизатор. Я новичок в Java и откровенно не совсем понимаю, что он делает, но я знаю, что он принимает вход от пользователя и пытается заставить его хранить кучу переменных для меня. Вот код:Ввод Java не принимается readline
// import required packages for the program, importing all classes from packages to be on the safe side
import java.io.*;
import java.util.*;
import java.text.*;
public class Example
{
// need to use throws IO Exception because we are dealing with input and output, simple main method will not suffice
public static void main(String[] args) throws IOException
{
// declare department names as strings
String department1;
String department2;
String department3;
String department4;
// declare number of employees in each department as ints
int employees1;
int employees2;
int employees3;
int employees4;
// declare cost per employee in each department as doubles
double cpe1;
double cpe2;
double cpe3;
double cpe4;
//declare sales in each department as doubles
double sales1;
double sales2;
double sales3;
double sales4;
// declare in as a BufferedReader- used to gain input from the user
BufferedReader in;
in = new BufferedReader(new InputStreamReader(System.in));
//get input from the user to define department names
System.out.println("What is the name of department 1?");
department1 = in.readLine();
System.out.println("What is the name of department 2?");
department2 = in.readLine();
System.out.println("What is the name of department 3?");
department3 = in.readLine();
System.out.println("What is the name of department 4?");
department4 = in.readLine();
System.out.println("\n");
//get input fromm the user to define number of employees
System.out.println("How many employees are in department 1?");
employees1 = in.readLine();
System.out.println("How many employees are in department 2?");
employees2 = in.readLine();
System.out.println("How many employees are in department 3?");
employees3 = in.readLine();
System.out.println("How many employees are in department 4?");
employees4 = in.readLine();
System.out.printlin("\n");
// get input from user to define cost per employee in each department
System.out.println("What is the cost per employee in department 1?");
cpe1 = in.readLine();
System.out.println("What is the cost per employee in department 2?");
cpe2 = in.readLine();
System.out.println("What is the cost per employee in department 3?");
cpe3 = in.readLine();
System.out.println("What is the cost per employee in department 4?");
cpe4 = in.readLine();
// get input from user to define sales in each department
System.out.println("What are the sales in department 1?");
sales1 = in.readLine();
System.out.println("What are the sales in department 2?");
sales2 = in.readLine();
System.out.println("What are the sales in department 3?");
sales3 = in.readLine();
System.out.println("What are the sales in department 4?");
sales4 = in.readLine();
Я получаю ошибку о том, что несовместимые типы происходит, когда я пытаюсь запустить программу. Опять же, очень новый для этого, поэтому любые простые объяснения были бы очень оценены. Спасибо!
Можете ли вы добавить подробную трассировку стека и ввод, который вы используете? –
Спасибо, что задали хороший вопрос. Я не знаю достаточно о Java, чтобы помочь вам, но мы ценим, что вы задали реальный вопрос, а не только тему типа «дайте мне-тез-код». +1 – OneChillDude
Я предлагаю вам использовать 'java.util.Scanner', он имеет несколько полезных методов (например,' nextDouble() '). –