0

The program should take two inputs and display them. However when i run it, it ask only my Age and then it prints it out. I want that the program would ask also my name.

You are 16 years old Your name is:

import java.util.Scanner;

public class NIMEVALIK{
int Vanus;
String NIMI;


public void setAge(int vanus){
    Vanus = vanus;
} 
public void setName(String name){
    NIMI = name;
}
public int getAge() {
    System.out.println("Your are %s years old: ",Vanus);
    return Vanus;
}
public String getName(){
    System.out.println("Your name is: " + NIMI);
    return NIMI;
}

public static void main(String[]args){
    int age;
    String name;
    NIMEVALIK nimiObject = new NIMEVALIK();
    Scanner input = new Scanner(System.in);
    System.out.println("Siseta vanus");
    age = input.nextInt();
    nimiObject.setAge(age);
    System.out.println("sisega nimi");
    name = input.nextLine();
    nimiObject.setName(name);
    nimiObject.getAge();
    nimiObject.getName();

}
}   
m2rt
  • 157
  • 2
  • 12
  • Possible duplicate of [Scanner issue when using nextLine after nextXXX](http://stackoverflow.com/questions/7056749/scanner-issue-when-using-nextline-after-nextxxx) – PakkuDon Apr 05 '14 at 04:47

2 Answers2

1

Your code:

        name = input.nextLine();

Try This :

        name = input.next()+input.nextLine();
Benjamin
  • 2,257
  • 1
  • 15
  • 24
0

before this line:

name = input.nextLine();

add:

input.nextLine(); //junk
CMPS
  • 7,733
  • 4
  • 28
  • 53