Presentation is loading. Please wait.

Presentation is loading. Please wait.

Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.

Similar presentations


Presentation on theme: "Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner."— Presentation transcript:

1 Martin T. Press

2  Main Method and Class Name  Printing To Screen  Scanner

3 The Return Type : always void (means returns nothing) The parameters Of the method: The Main Method Away takes a list of type String The main method is the starting point of execution of the Java program. Without a main Method a Class is not runnable by itself. A Java project must have at least one class with a main. Most of the first few labs will have one class. Remember always include public static at the beginning of the method. If this is left out the complier will not recognize it as the “main”.

4 File Name Sum.java The Public Key word tells the complier that all classes can see it ! I Class Name Sum Every.java file written must have a class name. It must be the same name as the.java file. Failure to name it the same as the file name will cause a compile error.

5 The System.out.print() and System.out.println() will be the only visual output for the first few labs. It displays text that is inside the ( ). The + operator when used with strings pushes them together. Such that “Hello ”+5 is the same as the String “Hello 5”. This is useful when printing!

6 Scanner Is the object that allows programs to get Input data from the user on the command line. The two methods we will use in this lab are nextDouble() and nextInt() This is the import statement which tells the complier where the Scanner object is located in the java library. You must always include this when scanner is used. This is a constructor for the Scanner (creates the object). It always takes System.in as a parameter for reading the command line. myScanner.nextDouble() Returns the next double entered by the user(Waits till user hits enter).

7 This is the output from the previous example of code. Notice that even if an integer is entered the output is still a double for the double. Try it the other way around what happens?

8 Looks like an error occurred. Last time it worked because of type casting. A good rule of thumb is if the scanner is expecting a type to always input the same type.


Download ppt "Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner."

Similar presentations


Ads by Google