Test Review CSC 115 Midterm 1 Flashcards
Test Prep
How to print in Java?
System.out.println()
What does a Java program always start with?
Class Declaration with Class name(public class _____)
What is the equivalent of functions(blocks of code) in Java?
Methods
Allows us to convert a value from one type to another
Casting
Converting a variable to another of higher precision
Implicit casting
Example:
int i = 4;
double j = i; // j is 4.0
Forcing the conversion of a variable to a specified type
Explicit casting
Example:
double x = 4.95; // x is 4.95
int y = (int) x; // y is 4
How to declare Methods?
public static <returnType> <name> (<parameters>) {
statement inside method;
}</parameters></name></returnType>
“and” operator
&&
“or” operator
||
- Always execute the block of code once
- and continue to execute the block of code as long as a specified condition is met
do-while loops
How to declare an array if we know what values to put in it?
type[] name = {<comma>};</comma>
How to declare an array if we don’t know what values to put in it(only know the size or know nothing at all)?
type[] name = new type[<size>];</size>
What can we use to determine the length of an array?
int[] numsArray = {7, 9, 6, 4};
System.out.println(numsArray.length); //outputs 4
How to declare Multi-dimensional Arrays?
int c[][] = new int[3][4];
or
int c[][] = {{1, 2}, {3, 4, 5}, {6, 7}, {8, 9, 10}};
Error caused by improperly formatted code(missing semicolons/wrong capitalizations)
Syntax errors