Java program error (spacing)

As i created this voting program where user enter name and age. If user age is less then 18 then program say (you are not eligible for voting)
If user enter name like (Raza) then this program work properly.
this program work properly but problem is when user enter name like (Ahmad Raza)
mean with space two names then this program not work. why?

Program Code:

import java.util.Scanner;

public class voting_app {
public static void main(String[] args)
Scanner sc = new Scanner(;
System.out.println(“Enter your Name”);
String name =;
System.out.println(“Enter your age”);
int age = sc.nextInt();

  if(age > 18)
	  System.out.println( "Welcome "+ name + "!" + " You are eligible for voting");
	  System.out.println(" You are not eligible for voting");


When you taking input in String name you write; you have to just change to it sc.nextLine(); tehn you can make input with space

1 Like

Thank You Soo Much Mr.namantech25 for your kind information.