0
How to ask a custom question and store the answer inputted by the user in java?
So I am trying to develop a code in which the user is asking his/her name and then their response is stored and is used in order to greet them. Then they are asked their marks and then according to the answer a custom result will be produced. This is what I have done until now. (The code isn't executing either): https://code.sololearn.com/craoR83D7Xpz/#java Thanks in advance
2 Answers
+ 3
Youâve got a couple problems, firstly youâre using Scanner wrong.
Next, you need to import Scanner by typing âimport java.util.Scannerâ at the top of your code. Youâve also got a couple of misspelled print functions, if you compare the top half of your code with the functional edited version I wrote below, you should see your mistakes:
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
System.out.println("What is your name");
Scanner scan = new Scanner(System.in);
String name = scan.nextLine();
System.out.println("Welcome " + name);
// This will ask the user name and then print a response saying welcome "the user's name".
System.out.println("What are your marks");
int marks = scan.nextInt();
if(marks == 100){
+ 1
Install Java IDE at a computer for interactivity of your program