ACS1 Semester One Exam Flashcards

5.0(1)
studied byStudied by 8 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/34

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

35 Terms

1
New cards

int

int (name) = 3

Whole numbers (e.g., 5, -10)

2
New cards

double

double (name) = 3.4;

Decimal numbers (e.g., 3.14, -0.5)

3
New cards

boolean

i.e. boolean (name) = true/false;

True or false values (true, false)

4
New cards

String

String (name) = “Your mom.com”;

A sequence of characters (e.g., "Hello", "CodeHS") - use quotes

5
New cards

Variable Rules

  • Must start with a letter, , or $ (e.g., myVar, value).

  • Cannot start with numbers or use reserved keywords like class.

6
New cards

Type Casting:

Example: Convert int to double

int x = 5;  

doubley=(double)x; //y is now 5.0

7
New cards

Creating a string

String greeting = "Hello";

8
New cards

Write a small program to print out the length of the word “asdfafd”

String word = “asdfafd”;

System.out.println(word.length());

9
New cards

Write a small program to turn the word “grah” to all uppercase.

System.out.println(“grah”.toUpperCase());

10
New cards

Write a program to find the char at the index of 3 in “dogs”.

String s = “dogs”;

System.out.println(s.charAt(3));

11
New cards

How do you write equal to as a comparison operator?

==

12
New cards

How do you write not equal to as a comparison operator?

!=

13
New cards

How do you write greater than as a comparison operator?

>

14
New cards

How do you write greater than or equal to as a comparison operator?

>=

15
New cards

How do you write less than as a comparison operator?

<

16
New cards

How do you write less than or equal to as a comparison operator?

<=

17
New cards

How do you write AND as a logical operator?

&&

18
New cards

How do you write OR as a logical operator?

||

19
New cards

How do you write NOT as a logical operator?

!

20
New cards

How do you write an if statement?

if (condition) {

}

21
New cards

How do you write an if-else statement?

if (condition) {

}

else {

}

22
New cards

How do you write an else-if statement?

if (condition) {

}

else if{

}

23
New cards

Write a program that prompts the user to input an int, which is y. if int y >= 10, the console prints “Greater than or equal 10”, and if it’s lower than ten, it prints “Less than 5”.

Scanner input = new Scanner(System.in);

int y = input.nextInt();

if (y >= 10){

System.out.println(“Greater than or equal 10”);

}

else{

System.out.println(“Less than 5”);

}

24
New cards

What is the main class name?

public static void main(String[] args)

25
New cards

What does the first value in a for loop do?

Initializes the variable

26
New cards

What does the second value in a for loop do?

Sets the if condition.

27
New cards

What does the third value in a for loop do?

Makes the change in the variable

28
New cards

Write a for statement that repeats until i equals 5 while adding 1 everytime starting from zero, printing i every repition.

for(int i = 0; int <= 5, i++){

System.out.println(i);

}

29
New cards

What’s a for loop?

Use when you know how many times to repeat the loop.

30
New cards

What is while loop?

Use when the number of repetitions depends on a condition.

31
New cards

Write a while statement that repeats until count equals 2 while adding 1 everytime starting from zero, printing count every repition.

int count = 0;  

while (count < 3) {  

    System.out.println(count);  

    count++;  

}  

32
New cards

Infinite Loops example?

while (true) {  

    System.out.println("This will run forever!");  

33
New cards

What is the output of the following code?


int a = 8;  

double b = 3.0;  

System.out.println(a / b);  


a. 2
b. 2.0
c. 2.6666666666666665
d. Error

c. 2.666666666666665

34
New cards

What is the result of true && false?
a. true
b. false
c. Error
d. 0

b. false

35
New cards

Write a for loop to print numbers 1 through 5.

for(int i = 1; i < 6; i++){

System.out.println(i);

}