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);

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!!!!

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.