hi i don't have my book with me and i can't remember what is the code for let's say, the console asks "please enter your name" what would be the code for wanting to take what they type and assign a value like name = "whatever they type"

system.out.println("Please enter your name")

what would the code be to go after that?
sorry i'm very new to all of this

eikal,

You will want to instantiate a String to store the name you want to store the name in, after that do you will use your print code, then read it in using a Scanner's nextLine() method.

import java.util.Scanner;

public class DaniProject{
	public static void main(String [] args){
		String name; // String to store the name inputted.
		Scanner input = new Scanner(System.in); // Scanner object to store the InputStream of the Prompt.
		
		System.out.println("Enter your name:");
		name = input.nextLine().trim(); // Store whatever the user entered into the name String without 
					// trailing whitespace.
	}
}

Welcome, any further questions, just PM me,

cbarton.a

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.