INTERMEDIATE PROGRAMMING. Midterm Quiz.
INTERMEDIATE PROGRAMMING. Midterm Quiz.
Midterm Quiz
INTERMEDIATE PROGRAMMING
Name: Program:
Student Number: Year level:
Directions:
Part I:
1. Refer to Java Program Coding and Debugging Class discussions and
presentation. (Item 1-4).
2. Give the Program title functions and descriptions. (Item 1-4 only)
3. Place the following after each item: (Note: Source line number is located at the
end of each statement.).
3.1. Error codes with explanation
3.2. Debugging codes with explanation
package javaternaryoperator;
Some programmers don’t include to indicate the package name
in the source code program but it is also important because
when we named a folder it will automatically shows in the
program when we start to encode.
String result;
I removed the equal sign (=) before the semicolon (;)
Error codes with explanation
2.4. incompatible types: boolean cannot be converted to String (8)
This error shows because there is a value of a certain data type different from
the one expected. Or there is really something wrong in the whole source line
programs that is why Java compiler is unable to resolve a value assigned to a
variable.
int a = 4;
Follow the processing of codes in chronological order and observe if there
are changes happened that is not match in the variable that we are
declaring.
Error codes with explanation
3.2. Invalid method declaration; return type required (3)
This error shows because there is a missing code. We must know the correct
code to return a void method.
var = a;
After creating a variable, it is important to assigned a data type to its
designated purpose.
4. Java Increment and Decrement Operators
Increment and decrement operator is used to increase and decrease the
variable by one. Increment increases the variable by 1 (++a) while decrement is
to decrease the variable by one (--b).
result1 = ++a;
result2 = --b;
Always insert the incremental operator (++) and decrement operator (--)
with the variable for us to successfully declare the things that we want to
do with the int. and to run it successfully.
This error line shows because the declaration of my variable didn’t have initial
value.
Debugging codes with explanation
Always initialized the value first by encoding type name = expression
because it is where the initializer combines the declaration statement
and assignment statement into concise statement.
Error codes with explanation
4.4. reached end of file while parsing (20)
This line error pertains to the missing closing curly braces ( } )because we
cannot end the program and be able to run it successfully if we didn’t end or
close it properly.
}
Always put curly braces at the last part of the program to end it properly
and be mindful on its purpose if it is for the main group or sub group of
the program.
1. Java Input
a. Functions
The data that the user give to the program.
b. Examples
2.Java print()
a. Functions
This method is used to display a text/string inside the quotation
mark on the console.
b. Examples
b. Examples
int age = 24; (Variable)
int a = 1; (literals)
5.Java Output
a. Functions
To send output into a standard output and be able to accept the
output data in the program.
b. Examples
6. Java println()
a. Functions
println adds new line after print text on console
b. Examples
7.Java Get float
a. Functions
Data types used to represent decimal values or floating point literals
b. Examples
System.out.print("Enter float: ");
float myFloat = input.nextFloat();
System.out.println("Float entered = " + myFloat);
b. Examples
System.out.print("Enter text: ");
String myString = input.next();
System.out.println("Text entered = " + myString);
b. Examples
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Operation
b. Examples
b. Examples
Boolean type (true,false)
Byte Type (-128 – 127/ 8-bit)
Short Type ( -32768 to 32767/ 16-bit )
Int Type (-2^31 to 2^31-1 /32-bit)
Long Type (-2^63 to 2^63-1 64-bit)
Double Type (64-bit floating-point)
Float Type (32-bit floating-point.)
Char Type (16-bit Unicode character)