COP 2258 exam 1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Identifier rules

be a sequence of characters that consist of letters, digits, underscores (_), and dollar signs ($) start with a letter, an underscore (_), or a dollar sign ($). It cannot start with a digit not be a reserved word not be true, false, or null can be any length

Which of the following is are incorrect ways to include multi-line comments in your code? /*Declare all variables/* */Declare all variables*/ */Declare all variables/* /*Declare all variables*/

/*Declare all variables/* */Declare all variables*/ */Declare all variables/*

Choose the best type for each of the following variables to represent each item: 1. The amount of money in the back. 2. The number of hairs on a person's head. 3. The average score earned on an exam. 1. double 2. int 3. double 1. double 2. double 3. double 1. int 2. int 3. int 1. int 2. int 3. double 1. double 2. int 3. int

1. double 2. int 3. double

What is the Java source filename extension? What is the Java bytecode filename extension? 1.) .class 2.) .jv 1.) .class 2.) .java 1.) .java 2.) .js 1.) .java 2.) .class

1.) .java 2.) .class

How do you denote a comment line? How do you denote a comment paragraph? 1.) // 2.) /* /* 1.) *// 2.) // 1.) /* 2.) /*/ 1.) // 2.) /* */

1.) // 2.) /* */

Programming Life Cycle Phases

1.Problem Solving 2.Implementation 3.Maintenance

Suppose that the input is 5. Consider the following code. Scanner console = new Scanner(System.in); int alpha = 7; int beta = console.nextInt(); switch (beta) { case 5: alpha = alpha + 1; case 6: alpha = alpha + 2; case 7: alpha = alpha + 3; default: alpha = alpha + 5; } System.out.print(alpha); What is the output of the following code? 10 18 14 15 17

18

When was the first public release of Java? 1994 2000 1995 1998 1991

1995

int x = 46; int y = 3; switch (x % 9) { case 0: case 1: y++; case 2: y = y - 2; break; case 3: y = y + 2; case 4: break; case 5: case 6: y = y + 3; } System.out.println(y); 6 46 5 3 2

2

After the execution of the following code, what will be the value of num if the input value is 4? Scanner console = new Scanner(System.in); int num = console.nextInt(); if (num > 5) num = num + 10; else if (num >= 3) num = num + 17; System.out.println( num ); 4 31 21 14

21

Assume the following code: String team = "Florida State Seminoles"; System.out.println( team.length() + " " + team.substring(1,6)); What is the result of the above code? 23 lorid 23 lor 24 lori 23 lorida 24 lorida

23 lorid

What is the result of the following statement? Math.pow(3.0, 3.0) 9 20 6 27

27

Suppose the following strings are declared as follows: String city1 = "Miami"; String city2 = "Orlando"; What is the results of the following expressions? city1.concat( city2).lastIndexOf( 'a' ); 5 9 8 7 10

8

int x, y; if (x < 4) y = 2; else if (x > 4) { if (x > 7) y = 4; else y = 6; } else y = 8; Based on the code above, what is the value of y if x = 4? 8 6 4 2

8

If numMarbles is initally 89, what is numMarbles after the following code executes? 90 94 89 4 93

93

Class Vs. Object

Class: a description of the representation of a specific kind of object, in terms of data and behavior. Object: an instance of a class.

Assume the following: String userName = "Jessica"; The following code will return 'a': userName.charAt( userName.length() ) True False

False

In Java, || has a higher precedence than &&. True False

False

The code below outputs Jane Williams on different lines and then starts a new output line. Code Example: System.out.println("Jane"); System.out.print("Williams"); Output: Jane Williams T or F

False

The following code segment correctly tests for equality: String month = "October"; if (month == "October") { System.out.println("The month is October."); } True False

False

The following statements correctly calculate the numDays: int numDays; int numYears; numDays = numYears * 365; T or F

False

Which of the following is considered good practice for fixing errors reported by the compiler? Focus on the last error message an, fix it and ignore the rest of the errors initially. Focus on first error message, fix it and ignore the rest of the errors initially. Focus on the next to the last error message, fix it and ignore the rest of the errors initially. None of these

Focus on first error message, fix it and ignore the rest of the errors initially.

Implicit vs Explicit casting

Implicit: type widening Explicit: type narrowing

When a new programmer complains: "The program compiled perfectly but isn't working." , what type of errors are these typically? Compile-time errors Logic errors Run-time errors Syntax errors

Logic errors

What will the following code output? Code: int feet = 5; int inches = 3; System.out.print("Mary you are " + feet + " feet " + inches + " inches tall."); Mary you are 5 feet 3 inches tall. Mary you are feet inches tall. Mary you are feet feet inches inches tall. "Mary you are " + 5 + " feet " + 3 + " inches tall." "Mary you are " + feet + " feet " + inches + " inches tall."

Mary you are 5 feet 3 inches tall.

A __________ is a text parser that can get numbers, words, or phrases from an input source such as a keyboard. Scanner Method Print System.out

Scanner

What type of error means that the programmer violated a programming language's rules on how symbols can be combined to create a program? Syntax error Buffer error Logic error Command line error

Syntax error

Which of the following statements will allow you to print the name Mary Smith to the screen? Input("Mary Smith"); Scanner name.next("Mary Smith"); System.out.print("Mary Smith"); System.in("Mary Smith");

System.out.print("Mary Smith");

Suppose that s1, s2, and s3 are three strings, given as follows: String s1 ="To Be, or not to be,"; String s2 = "That is the question:"; String s3 = "Whether 'tis nobler in the mind to suffer"; What is the results of the following expressions? s2.concat(s1) Whether 'tis nobler in the mind to sufferTo Be, or not to be, To Be, or not to be,That is the question: That is the question:To Be, or not to be, That is the question:Whether 'tis nobler in the mind to suffer

That is the question:To Be, or not to be,

What is computer programming?

The process of specifying the data types and the operations for a computer to apply to data in order to solve a problem.

A character is stored in memory as a number. For example, 'N' is stored as 78 in memory. True False

True

It is good practice to deliberately and consistently use whitespace to make a program more readable. Programmers usually follow conventions defined by their company, team, instructor, etc., such as: Use blank lines to separate conceptually distinct statements. Indent lines the same amount. Align items to reduce visual clutter. Use a single space before and after any operators like =, +, *, or << to make statements more readable. T or F

True

Which of the following is a valid variable name? depositFunds 5String int 89#Height

depositFunds

What will the following resulting type be, given the following expression? Assume numSales1, numSales2, and totalSales are int variables. (double)(numSales1 + numSales2) / 2 char String int double

double

Which of the following statements best declares and initializes a double variable? double depositFunds = $55.69; double depositFunds = $56; double depositFunds = 55.69;

double depositFunds = 55.69;

Which of the following statement is a valid declaration and use of a constant double variable named INTEREST_RATE? int INTEREST_RATE = 2.97; final int INTEREST_RATE = 2.97; FINAL INT INTEREST_RATE = 2.97; INTEREST_RATE = 2.97;

final int INTEREST_RATE = 2.97;

What is an algorithm?

instructions for solving a problem in a finite amount of time using a finite amount of data.

Which method in the Scanner class reads until it reaches a whitespace character? In other words, this method allows you to read one word at a time. nextLine() nextDouble() next() nextString() nextInt()

next()

What is a variable?

used to store data.

Assume x=4 and y=5, which of the following is true? !(x == 4) ^ y != 5 x == 5 ^ y == 4 x != 4 ^ y == 5 x != 5 ^ y != 4

x != 4 ^ y == 5

Assume x = 4 and y = 5, which of the following is true? x < 5 || y < 5 x < 5 && y < 5 x > 5 && y > 5 x > 5 || y > 5

x < 5 || y < 5

Given the following code, convert the if-else statement to a single assignment statement using a conditional expression. if (x > 30) { y = 20; } else { y = x; } y = x ? 20 : (x > 30); y = ( x > 30) ? 20; y = 20 ? (x > 30) : x; y = ( x > 30) ? 20 : x;

y = ( x > 30) ? 20 : x;

What is the output of the following Java code? int x = 0; if (x > 0) System.out.println("positive "); System.out.print("zero "); System.out.println("negative"); negative zero negative zero positive zero negative

zero negative


Kaugnay na mga set ng pag-aaral

Chapter 17: The Cardiovascular System

View Set

Ch 7- Business Strategy: Innovation and Entrepreneurship

View Set

Final Back of Book Questions: Astha (258-268), Ashley (269-279), Aarti (280-290)

View Set

Chapter 11 - Network Performance and Recovery

View Set

CC6003 Digital Crime Investigation quiz 6, CC6003 Digital Crime Investigation quiz 4, Digital Crime Investigation quiz 5, CC6003 Digital Crime Investigation quiz 3, DCI Review Questions 2, DCOM258: Quiz6: Networking Protocols and Threats(Ch7)

View Set