hello can you help me please how can input text with space..

sample:
Enter your full name: jemz gimz
Enter your company name: company one

jemz gimz company one

import java.util.*;

public class SampleNexLine
{
	  public static void main(String []args)
	  {
	  
	    Scanner console = new Scanner(System.in);
	    
	    String name,cname;
	    
	    System.out.print("Eter Your Full Name: ");
	    name=console.nextLine();
	    
	    console.nextLine();
	    
	    System.out.print("Enter your Company Name: ");
	    cname =console.nextLine();
	 
            console.nextLine();

	    System.out.println(name + cname);
	  } 	  	   
	  
}
 
can  you help me please...thank you in advance hoping for your positive response

If you want a space between the 2 different outputs at the end, just add an empty string.

System.out.println(name +" "+ cname);

Edited 5 Years Ago by Akill10: n/a

If you want a space between the 2 different outputs at the end, just add an empty string.

System.out.println(name +" "+ cname);

sir thank you for the reply but that is not my point sir,

how am i going to input string with space

sample:

enter your name: jemz gimz

can input with space...can you help me sir thank you in advance hoping for your positive response...

sir thank you for the reply but that is not my point sir,

how am i going to input string with space

sample:

enter your name: jemz gimz

can input with space...can you help me sir thank you in advance hoping for your positive response...

Ok...the reason I assumed that was not what you were asking is because your program already allows you to do that. The name=console.next() takes the whole input, spaces and all. Have you not tried to run your code?

The only place in your code where there is no space showing in the output is the final print statement, which I showed you in my last post. Also, everywhere you see console.next() on its own, remove it, it is uneeded.

name=console.nextLine();
	    
	    console.nextLine();///REMOVE THIS, IT IS UNECESSARY, YOU HAVE ALREADY TAKEN INPUT ABOVE
	    
	    System.out.print("Enter your Company Name: ");
	    cname =console.nextLine();
            console.nextLine();///REMOVE THIS ALSO. AGAIN, IT IS UNECESSARY, YOU HAVE ALREADY TAKEN INPUT ABOVE

Other than removing those lines and adding a space to your final print, your program already does what you are asking help for!!!!

Edited 5 Years Ago by Akill10: n/a

This question has already been answered. Start a new discussion instead.