This is my code for the solution. I have always used scanner in the passed before I started taking this codeGym course. I understand that it probably wants me to use the bufferedReader, but from what I've seen the bufferedReader can only take a String value. Why do we want to use bufferedReader instead of Scanner? To me it makes more sense to use the nextInt(); followed by nextLine; rather than parsing the string to an int each time. I am also wondering why the main method has the
throws Exception
If anyone is able to explain this to me I would appreciate it, I am just trying to get a better understanding.
package club.pillowmc;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name = input.nextLine();
int salary = input.nextInt();
input.nextLine();
int years = input.nextInt();
input.nextLine();
System.out.println(name + " will receive " + salary + " in " + years + " years.");
}
}
package com.codegym.task.task03.task0319;
/*
Predictions
*/
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
String name = input.nextLine();
int salary = input.nextInt();
input.nextLine();
int years = input.nextInt();
input.nextLine();
System.out.println(name + " will receive " + salary + " in " + years + " years.");
}
}