How does this program actually work...?
import java.util.Scanner;
class string
{
public static void main(String a[]){
int a;
String s;
.nextInt() gets the next int, but doesn't read the new line character. This means that when you ask it to read the "next line", you read til the end of the new line character from the first time.
You can insert another .nextLine() after you get the int to fix this. Or (I prefer this way), read the int in as a string, and parse it to an int.