"Hi, Amigo. You're doing great. Here is a new exercise for you: write a program that accepts some data from the keyboard and displays text that uses that data:"
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();
int number = scanner.nextInt();
System.out.println(name + " will take over the world in " + number + " years. Mwa-ha-ha!");
Doesn't work and I don't know why
Nvm, figured that out, here's the code for everyone strugglin:
package en.javarush.task.jdk13.task03.task0318;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
How to take over the world
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();
String sNumber = reader.readLine();
int number = Integer.parseInt(sNumber);
System.out.println(name + " will take over the world in " + number + " years. Mwa-ha-ha!");
}
}
you dont even need to parse int from the input text because there is no need in representation of it as a number. System.out.println wants a string, and you can leave it a String, without making unnecessary transformations ;)
well, the first task is definitely not for level 2... It was a poor explanation in the lesson, so there is close to no chance of completing the task without additional research
GO TO FULL VERSION