0% found this document useful (0 votes)
69 views11 pages

Lesson 3 Importing Java Packages To Make Them

The document discusses importing Java packages and using the Scanner class. It provides examples of how to import packages like java.util for the Scanner class and collections framework. It also shows how to create Scanner objects to read from keyboard, files, or other inputs. Methods like nextInt(), nextLine(), and close() are demonstrated. The document also briefly covers if/else statements and switch statements for conditional logic. Finally, it defines arrays as groups of variables of the same type that can be one-dimensional or multi-dimensional and provides syntax examples.

Uploaded by

Gel Basabe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views11 pages

Lesson 3 Importing Java Packages To Make Them

The document discusses importing Java packages and using the Scanner class. It provides examples of how to import packages like java.util for the Scanner class and collections framework. It also shows how to create Scanner objects to read from keyboard, files, or other inputs. Methods like nextInt(), nextLine(), and close() are demonstrated. The document also briefly covers if/else statements and switch statements for conditional logic. Finally, it defines arrays as groups of variables of the same type that can be one-dimensional or multi-dimensional and provides syntax examples.

Uploaded by

Gel Basabe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lesson 3 Importing Java

Packages to make them


Accessible in the Code
 Java.util – contains the collections framework, legacy
collection classes, event model, date and time facilities,
internationalization and miscellaneous utility classes
 Package– technique for organizing java classes into
namespaces providing modular programming in Java
JAVA PACKAGES

 Scanner class is a class in java.util that allow the


user to read values from keyboard or file
Class Constructors

1. Scanner in = new Scanner(System.in);


2. Scanner inFile= new Scanner(new
FileReader(<<myFile>>));
Numeric and String Methods

METHOD RETURNS

intnextInt() Returns the next token as an int

long nextLong() Returns the next token as a long

float nextFloat() Returns the next token as a float

double nextDouble() Returns the next token as a long


Numeric and String Methods

METHOD RETURNS

String next() Finds and returns the next complete token


from this scanner and returns it as a string
string nextLine() Returns the rest of the current line, excluding
any line separator at the end.
void close() Closes the scanner
Java Selection Statements

1. The if statement is used to direct program execution in two different routes.


Here is the syntax of the if statement:
if (condition) starement1;
else statement2;
2. The switch statement is used for forward execution to different parts of the user’s program based on the value of an
expression
Heres the syntax of switch statement:
switch (expression){
casevalue1: //statement
break;
casevalue2: //statement
break;
Lesson 4: Demonstration the
Creation and Use of Arrays
Array

 Utilizedto save a group of data, but it is


frequently more beneficial to think of an array as a
group of variables of the same type.
 Fixed size objects
One dimensional array

 Can be viewed as a list of items in memory , stored sequentially.


The syntax of one-dimensional array declaration is like this:
typevar-name [];
Example: String hname[]={“SugarHotel”, CebuHotel”, “ApoNew
Hotel”};
doublerday[]={0,1106.00,930.90,920.30};
Multidimentional Array

 Stores a table of data, with rows and columns of values.


This is useful for storing more complex groups of related
items. It is best applied in string arrays.
 Synatax: typevar-name [][];
 Example: numbers = new int[10] [10];

You might also like