Question:

Strings...java...........

by  |  earlier

0 LIKES UnLike

import java.util.Scanner;

public class inputString {public static void main(String []args) { String inStr, inLine;

Scanner s = new Scanner(System.in);

inStr = s.next();

inLine = s.nextLine();

System.out.print(“inStr =” inStr);

System.out.print(“inLine=” inLine);

}

}

hmm shouldn't it be scanner sc... and sc.next(); and sc.nextLine();...

 Tags:

   Report

1 ANSWERS


  1. s is just the variable name: what the line 'Scanner s;' does is creates a variable called 's' of type Scanner. So when it gets to s.next() and s.nextLine(), (loosely) it looks up the variable called 's', it sees it's of type Scanner, and then calls the Scanner class's next() and nextLine() method.

    So you could replace it with sc if you wanted - you could call it anything (as long as it conforms to legal Java variable naming schemes)

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.