Wikipedia:Reference desk/Archives/Science/2018 November 11

= November 11 =

Java Programming
For java programming, what is the difference between read and next?

For example:

Let's say I import the java Scanner class. Then I proceed as follows:

Scanner userInput = new Scanner(System.in); System.out.print("Enter the number of students: "); int numberOfStudents = userInput.nextInt; System.out.println("The number of students you entered is: " + numberOfStudents);

My question is would this work if I replaced "int numberOfStudents = userInput.nextInt" with "int numberOfStudents = userInput.readInt"? What is the difference between next and read? When should one be used over the other?

ThunderBuggy (talk) 17:20, 11 November 2018 (UTC)
 * According to the documentation Scanner class does not have readInt method. Ruslik_ Zero 20:27, 11 November 2018 (UTC)
 * So I would have had to create a readInt method before using it then, right? And the "next" methods are included with the Scanner class? ThunderBuggy (talk) 03:29, 12 November 2018 (UTC)


 * We have a CompSci ref desk, BTW - however we've started here, so let's stay.
 * This isn't a general Java language question but, like nearly all Java questions, a question about different libraries used by Java. As Java has been around a while, there are many such libraries and they're often inconsistent.  If we started again, we wouldn't have so many of these variations.
 * For the  library class, this implements and extends the   class interface, which defines a   method.
 * What  does is that it allows   to read, identify and move past a series of "tokens" in the input stream. That means you can write an input loop for a long series of tokens with just a simple loop.  Then   extends this, so that it recognises different types of token, such as    to read integers.
 * Don't mess with  etc. by trying to rename or facade them as something else.  Otherwise you lose the advantage of using   in a consistent and clearly understood way. There is no   in   or.
 * comes instead from  rather than  .  This is part of   rather than.
 * Now we see the crucial difference!   is for chopping up bits of well-behaved data which are already loaded into memory.   though is for dealing with the nasty real world of outside interfaces, data sources which stop halfway or timeout.
 * So for what you're doing here, then yes, base it on  and , rather than   and  .   You're doing this because of the purposes of the different classes (  understands real world IO), not simply the different methods. Andy Dingley (talk) 13:55, 12 November 2018 (UTC)
 * is an interface, not class. So,  class implements it and extends   class. Ruslik_ Zero  20:43, 12 November 2018 (UTC)

Fat and the blood-brain barrier
According to Wikipedia the human brain is nearly 60 percent fat. Also according to Wikipeida fat cannot cross the blood–brain barrier, hence the need for the liver to convert fat into ketone bodies which can then cross the blood–brain barrier and nourish the brain during periods of starvation. "Unlike free fatty acids, ketone bodies can cross the blood-brain barrier". So explain to me how the brain came to be 60 percent fat if fat cannot reach the brain due to the blood–brain barrier. 200.122.209.78 (talk) 19:51, 11 November 2018 (UTC)
 * See Lipogenesis. There's a reason you can get fat even if most of your energy comes from carbohydrates (such as sugars or starch) or protein and not fat. Nil Einne (talk) 20:35, 11 November 2018 (UTC)