Professional Documents
Culture Documents
GUIDANCE:
File location
Place all your programs in the Desktop folder for easy access.
Link
Link the Java compiler to the directory where your programs reside. In our case the programs are in the
Desktop folder.
a. Open Command Prompt.
b. Navigate to the directory where your programs are placed. In our case we key this DOS command
through the keyboard in the Command Prompt
cd Desktop
c. Key this through the keyboard to link the java compiler to the directory
(Important notes: The JDK’s folder name depends on the JDK version. In our case it is “jdk1.7.0_45”. If you
are using a 32 bit version of JDK, it is located in “Program Files (x86)”.)
Compile
To compile the program, key this command in the Command Prompt
javac NameOfOurProgram.java
To use this class, import the library to your program by keying this
import java.util.Scanner;
(Important note: You can change the identifier “nameOfScanner” name to your preferred name.)
Just search for the complete list of Scanner input methods in the Internet.
/**
* @file Name of the Program (.java)
* @description Provide a description of the program/file
* (what is this file supposed to do)
* @course CCC 101 Section W
* @lab Lab Activity 3
* @date 09/20/2018
* @author YOUR SURNAME, Your First Name
*/
import java.util.Scanner;
Write a method and name it as addDigits. This method takes utmost five (5) digit integer parameter, say num.
This method adds all digits of an integer and returns the sum.
Write the complete program to test your method. Name your program as SumOfNumberDigitsProgram. Your
program should look like the Sample Dialogs below. Don’t forget to include the header part.
Sample Dialog 1:
Sample Dialog 2:
Write a method and name it as isBinaryNumber. This method takes utmost five (5) digit integer parameter, say
num. This method then checks the number if it is a binary number or not. It returns a boolean value – true when the
number is a binary number and false otherwise.
For example, 1101 returns true.
1021 returns false (since a binary number can only be composed of 1 and/or 0 digits).
Write the complete program to test your method. Name your program as CheckBinaryNumberProgram. Your
program should look like the Sample Dialogs below. Don’t forget to include the header part.
Sample Dialog 1:
Sample Dialog 2:
What to submit: