S
slayer_azure
This is a simple program that I have written in Grade 12 Information
Technology, and we were instructed to do the following, which is to
ask the user to enter an integer, then call a method and asked a user
to enter their full name. Input is done using the methods from the
Scanner class of the java.util.* package. When I run the program, the
first part runs correctly and I enter a number but after that it calls
the name() method and prints "Enter FULL name: " but then the program
ends without giving me the chance to enter a name. What am I doing
wrong? Help will be appreciated.
import java.util.*;
public class test
{
static Scanner kbRead=new Scanner(System.in);
static String fname;
public static void main (String[]args)
{
System.out.println("Enter a number: ");
int num=kbRead.nextInt();
name();
}
public static void name()
{
System.out.print("Enter FULL name:");
fname=kbRead.nextLine();
}
}
Technology, and we were instructed to do the following, which is to
ask the user to enter an integer, then call a method and asked a user
to enter their full name. Input is done using the methods from the
Scanner class of the java.util.* package. When I run the program, the
first part runs correctly and I enter a number but after that it calls
the name() method and prints "Enter FULL name: " but then the program
ends without giving me the chance to enter a name. What am I doing
wrong? Help will be appreciated.
import java.util.*;
public class test
{
static Scanner kbRead=new Scanner(System.in);
static String fname;
public static void main (String[]args)
{
System.out.println("Enter a number: ");
int num=kbRead.nextInt();
name();
}
public static void name()
{
System.out.print("Enter FULL name:");
fname=kbRead.nextLine();
}
}