0

From the PRO section: "You have two employees in your company. Write a program as input of the salaries and output total of both

Sample Input 1500 3200 Sample output 4700 Daaamn I'm so mad about this. It's have been 3 days im still stuck with the course cause of the scanner class. I don't know what I'm doing incorrectly My code for this: import java.util. Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in) int firstEmployeeSalary = 1500; scanner.nextInt(); int secondEmployeeSalary = 3200; scanner.nextInt(); System.out.println(firstEmployeeSalary + secondEmployeeSalary); } } This is giving me back the input 1200 and 1900, and expected output 3100 (damn what?). I need some help with that exercise. I think i need the great example of this to understand the basics. Have a nice evening :)

21st Jun 2021, 8:13 PM
Zuzanna Piecowska
Zuzanna Piecowska - avatar
3 Réponses
+ 3
scanner.nextInt() read an integer ,you have to store it in a int variable. Zuzanna Piecowska do these changes : int firstEmployeeSalary =scanner.nextInt(); int secondEmployeeSalary = scanner.nextInt(); edit: //corrected code : import java.util. Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in) int firstEmployeeSalary = scanner.nextInt(); int secondEmployeeSalary = scanner.nextInt(); System.out.println(firstEmployeeSalary + secondEmployeeSalary); } }
21st Jun 2021, 8:29 PM
Jayakrishna 🇮🇳
+ 1
Damn i was so stupid, that was so easy I really appreciate your help, thanks mate!
21st Jun 2021, 9:00 PM
Zuzanna Piecowska
Zuzanna Piecowska - avatar
- 1
You're welcome...
21st Jun 2021, 9:11 PM
Jayakrishna 🇮🇳