Instructional Module and Its Components (Guide) : Course Ccs 3 Developer and Their Background
Instructional Module and Its Components (Guide) : Course Ccs 3 Developer and Their Background
(GUIDE)
COURSE CCS 3
DEVELOPER AND THEIR JOSELITO T. TAN
BACKGROUND Email:[email protected]
ANNA CAZANDRA DELOS REYES
Email:[email protected]
COURSE DESCRIPTION
COURSE OUTLINE Course Content/Subject Matter
Week 1 General Orientation and Introduction to Arrays
Week 2 Declaration and Creation of Arrays
Week 3 Array Processing and Array Class
Week 4 Strings
Week 5 String I/O
Week 6 String Manipulations
Week 7 String Manipulation Functions
Week 8 Review week and or submission of missed
assessments
Week 9 Midterm Exam (Written Exam)
Week 10 Creating Methods
Week 11 Calling Methods
Week 12 Passing by Value and by Parameter
Week 13 Java Swing
Week 14 Swing Components
Week 15 Discussion of contents of Final Requirement
(Group Case Study)
Week 16 Creation of Final Requirement (Group Case
Study)
Week 17 Submission of Peer evaluation
Week 18 Submission of Final Requirement (Group Case
Study)
One week
(or an
equivalent
of three
hours)
CHAPTER # 5
TITLE String I/O
I. RATIONALE
INSTRUCTION TO THE USERS Lectures are on this module. MS Teams will be used for showing the
actual demonstration of java programming.
At the start of the module, you are to take the pre-assessment test to see
how much information and knowledge you have about the java
programming.
As you go through the lessons, you can read, analyze and understand
that java programming is attractive as an alternative approach and how
does it differ from traditional programming languages.
II. LEARNING At the end of the chapter, students are expected to:
OBJECTIVES a. Learn the process of accepting and display string data from
the user.
III. CONTENT
In this lesson we are gonna see how to accept input from user. We are using Scanner class to get the input. In the below
example we are getting input String and integer.
Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double, etc. and strings.
It is the easiest way to read input in a Java program, though not very efficient if you want an input method for scenarios
where time is a constraint like in competitive programming.
To create an object of Scanner class, we usually pass the predefined object System.in, which represents the
standard input stream. We may pass an object of class File if we want to read input from a file.
To read numerical values of a certain data type XYZ, the function to use is nextXYZ(). For example, to read
a value of type short, we can use nextShort()
To read strings, we use nextLine().
To read a single character, we use next().charAt(0). next() function returns the next token/word in the input
as a string and charAt(0) function returns the first character in that string.
Let us look at the code snippet to read data of various data types.
// String input
System.out.println("Name: “);
String name = sc.nextLine();
System.out.println("Gender: “);
// Character input
char gender = sc.next().charAt(0);
System.out.println("Age: “);
// Numerical data input
// byte, short and float can be read
// using similar-named functions.
int age = sc.nextInt();
System.out.println("Mobile Number: “);
long mobileNo = sc.nextLong();
System.out.println("CGPA: “);
double cgpa = sc.nextDouble();
In this example, looping and array will be used in asking the user the size and dimension of the array. After which string
values will be ask to be inputted by the user and later on inputted string will be displayed.
Java String array is used to hold fixed number of Strings. String array is very common in simple java programs, specially
among beginners to java and to test some specific scenarios. Even java main method argument is string array – public
static void main(String[] args). So today we will look into different aspects of java string array with example programs.
Note that we can also write string array as String strArray[] but above shows way is the standard and recommended
way. Also in the above code, strArray is null whereas strArray1 value is [null, null, null].
class Main {
public static void main(String[] args) {
// create an array
String[] city = new String[] {“Tarlac City”, “Quezon City”,”Caloocan City”};
}
}
Output:
Accessing Elements of Array:
First Element: Tarlac City
Second Element: Quezon City
Third Element: Caloocan City
class Main {
public static void main(String[] args) {
// create an array
}
}
Output:
Using for Loop:
Basketball
Baseball
Swimming
Example
import java.util.Scanner;
public class ArrayInput
{
public static void main(String args[])
{
int m, n, i, j;
Scanner sc=new Scanner(System.in);
Output
In Java, an object is created from a class. We created the class named io, so now we can use this to create objects.
To create an object of io, specify the class name, followed by the object name, and use the keyword new:
Example:
Output:
First Name :John
Last Name :Doe
Example
Output:
1. Write a java program that will use looping, array and string
datatype that will accept 10 students name. Each student will
be ask to input 3 grade. The system will then diplay the
students name, the 3 grades and the average of the grades.
1. Write a java program that will accept 10 employee name and display
those name in their original sorted form and in their reverse form.
Example:
Employee 1: Joe
Employee 2: Karen
Employee 3: Franz
Original Form:
Joe
Karen
Franz
Reverse Form
Franz
Karen
Joe
REFERENCES Java Programming: Concepts and Applications, 6e – Joyce
Farell