computer programming flashcards

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/9

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.

10 Terms

1
New cards

What will this code segment output?

System.out.println("Hello");
System.out.println("World");

Hello
World

2
New cards

Which code segment will print “Hello Karel” to the screen in Java?

  1. Correct Answer

    System.out.println("Hello Karel");
    

3
New cards

What will this code segment output?

public class Printing
{
    public static void main(String[] args)
    {
        System.out.println("*****");
        System.out.println("****");
        System.out.println("***");
        System.out.println("**");
        System.out.println("*");
    }


  1. It will only print the first line as ***** since only one print statement can be used.

  2. Correct Answer

    *****
    ****
    ***
    **
    *

4
New cards

What is the correct syntax for writing the main method in Java?

public static void main(String[] args)
{

}

5
New cards

Which of the following is a proper way to declare and initialize a variable in Java?

int myNumber = 10;

6
New cards

Consider the following code snippet.

public static void main(String args[]){
    final int z;
    z = 20;
    z = 30;
    System.out.println(z);
}

What value of z is actually printed?

This code gives an error.

7
New cards

What are the memory values associated with the variables x, y, and z after the code snippet below executes?

int x = 7;            
double y = 2.0;             
boolean z = false;

x = x + 3;             
z = true;

x holds the int value 10, y holds the double value 2.0 and z holds the boolean value true.

8
New cards

Which of the following variable names follows best practices for naming a variable?

numApples

9
New cards

What does the keyword final do?


It prevents variables from being altered.

10
New cards

What will be the output of the following code snippet:

public class Variables 
{
    public static void main(String[] args)
    {
        int totalBirds = 150;
        double averageTime = 45.7;
        String mostCommon = "Mallard Duck";

        System.out.println("Bird Watching Results");
        System.out.print("Total birds seen: ");
        System.out.println(totalBirds);

        System.out.print("Average time between sightings: ");
        System.out.println(averageTime);

        System.out.print("Most common bird seen was ");
        System.out.println(mostCommon);
    }
}

Bird Watching Results
Total birds seen: 150
Average time between sightings: 45.7
Most common bird seen was Mallard Duck