How to ask a custom question and store the answer inputted by the user in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

2nd Aug 2019, 1:47 PM
Aryan Adhikari
Aryan Adhikari - avatar
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){
2nd Aug 2019, 4:12 PM
Jake
Jake - avatar
+ 1
Install Java IDE at a computer for interactivity of your program
2nd Aug 2019, 4:06 PM
Gordon
Gordon - avatar