What do I need to do in order to write my input on a new line in Java?

So after I input the numbers needed for the while instruction, it should display
the result and then the “Enter your name here:” text.
Afterwards I should be able to input text, but apperantly I can’t, it just displays the “Hello” message and jumps to the next instruction.

However, if I write the text right after the series of numbers, it works just fine. How can I make the program let me input text after the “Enter your name here” message?

import java.util.Scanner;

public class apples {
    public static void main(String[] args) {
        Scanner cristi = new Scanner(System.in);

        int age= 21, k=10, nr=1, sum=0, val=0;
        k=cristi.nextInt();
        while(nr<=k){
            val=cristi.nextInt();
            sum=sum+val;
            nr++;
        }
        sum=sum/k;
        System.out.println(sum);

        System.out.println(age>50 ? "You are old!" : "You are young!");

        tuna tunaObject= new tuna();
        System.out.println("Enter the name here: ");

        String a= cristi.nextLine();
        tunaObject.simpleMessage(a);

        System.out.println("Enter first name: ");
        String temp= cristi.nextLine();

        tunaObject.setName(temp);
        tunaObject.afisaj();         
    }
}

Add the line:

cristi.nextLine();

after the while loop to solve your problem.

Edit: @Xatyrian answer provides more context.

This is an issue about buffers and Scanner. To resolve your issue, just do cristi.nextLine() after each cristi.nextInt()so you clear the buffer.

For more info, you can look at this thread