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.
Problem
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.in);
System.out.println(“Enter your Name”);
String name = sc.next();
System.out.println(“Enter your age”);
int age = sc.nextInt();
if(age > 18)
{
System.out.println( "Welcome "+ name + "!" + " You are eligible for voting");
}
else
{
System.out.println(" You are not eligible for voting");
}
}
}