Sc.next() instead of sc.nextString()

So I was programming when I realized that after taking an integer input from user sc.nextString() does not work but sc.next() does, why?

sc.nextString() takes input as string and not as integer while next() takes the input in integer and string both. So basically you can either use sc.next() or sc.nextInt().

1 Like

@anon10100402 sc.next() usually take a word ( one string) as input from the user …if u want to type a large sentence ( a large line ) then use sc.nextLine();