1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius



Similar documents
Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Introduction to Java. CS 3: Computer Programming in Java

Building Java Programs

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Basics of Java Programming Input and the Scanner class

AP Computer Science Static Methods, Strings, User Input

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Building Java Programs

J a v a Quiz (Unit 3, Test 0 Practice)

Introduction to Programming

Chapter 2: Elements of Java

Interactive Applications (CLI) and Math

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Chapter 3. Input and output. 3.1 The System class

Part I. Multiple Choice Questions (2 points each):

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Chapter 2 Elementary Programming

Install Java Development Kit (JDK) 1.8

Topic 11 Scanner object, conditional execution

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

(Eng. Hayam Reda Seireg) Sheet Java

Sample CSE8A midterm Multiple Choice (circle one)

Introduction to Java

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Using Files as Input/Output in Java 5.0 Applications

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Lab 5: Bank Account. Defining objects & classes

CS 121 Intro to Programming:Java - Lecture 11 Announcements

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Introduction to Object-Oriented Programming

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Programming Languages CIS 443

Some Scanner Class Methods

Comp 248 Introduction to Programming

Building Java Programs

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

Java Crash Course Part I

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

LOOPS CHAPTER CHAPTER GOALS

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Programmierpraktikum

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

AP Computer Science Java Mr. Clausen Program 9A, 9B

CS170 Lab 11 Abstract Data Types & Objects

Object-Oriented Programming in Java

Programming Fundamentals I CS 110, Central Washington University. November 2015

CS 106 Introduction to Computer Science I

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Java CPD (I) Frans Coenen Department of Computer Science

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

JAVA ARRAY EXAMPLE PDF

13 File Output and Input

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Line-based file processing

1001ICT Introduction To Programming Lecture Notes

Java Basics: Data Types, Variables, and Loops

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

AP Computer Science File Input with Scanner

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Chapter 2 Introduction to Java programming

CS 106 Introduction to Computer Science I

6.1. Example: A Tip Calculator 6-1

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

The following program is aiming to extract from a simple text file an analysis of the content such as:

Lecture 5: Java Fundamentals III

Moving from CS 61A Scheme to CS 61B Java

Programming in Java Course Technology, a part of Cengage Learning.

Chapter 8. Living with Java. 8.1 Standard Output

Programming and Data Structures with Java and JUnit. Rick Mercer

In this Chapter you ll learn:

2 Getting Started with jgrasp 2.0

Interactive Programs and Graphics in Java

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Konzepte objektorientierter Programmierung

Arrays in Java. Working with Arrays

LAB4 Making Classes and Objects

Week 1: Review of Java Programming Basics

Arrays. Introduction. Chapter 7

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

Explain the relationship between a class and an object. Which is general and which is specific?

Programming in Java. What is in This Chapter? Chapter 1

Homework/Program #5 Solutions

Basic Java Syntax. Program Structure

While and Do-While Loops Summer 2010 Margaret Reid-Miller

Building Java Programs

How to use the Eclipse IDE for Java Application Development

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Transcription:

Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\t2night"); This statement will output lines of text a) 1 b) 2 c) 3 d) 4 e) 5 3) Which character below is not allowed in an identifier? a) $ b) _ c) 0 (zero) d) q e) ^ 4) Which of the following cannot cause a syntax error to be reported by the Java compiler? a) Mismatched b) Missing */ in a comment that begins with /* c) Missing ; d) Extra blank lines. 5) Which of the following statements will print a single line containing "hello there"? a) System.out.println( "hello" ); System.out.println( " there" ); b) System.out.println( "hello", " there" ); c) System.out.println( "hello" ); System.out.print( " there" ); d) System.out.print( "hello" ); System.out.println( " there" ); 6) Assume that x, y, and z are all ints equal to 50, 20, and 6 respectively. What is the result of x / y / z? a. 0 b. 12 c. 16 d. A syntax error as this is syntactically invalid e. A run-time error because this is a division by 0

7) What will be the value of z as a result of executing the following code? int x = 5, y = 28; double z; z = (double) y / x; a. 5.6 b. 5 c. 3.0 d. 5.0 8) What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5? a. 15 b. 105 c. 10 5 d. x+y e. An error since neither x nor y is a String 9) What is output with the statement System.out.println(""+x+y); if x and y are int values where x=10 and y=5? a. 15 b. 105 c. 10 5 d. x+y e. An error since neither x nor y is a String 10) Suppose x is 3. What is x after x *= 2? a. 4 b. 2 c. 6 d. 3 e. 8 11) The expression (int)(76.0252175 * 100) / 100.0 evaluates to. a. 76 b. 76.0252175 c. 76.03 d. 76.02 e. 76.0 12) Which of the following is not a syntax error? a. System.out.println( 'Hello world!' ): b. System.out.println( "Hello world!" ); c. System.out.println( "Hello" + "world!" ); d. System.out.println( Hello world! );

13) If you want to output the text "hi there", including the quote marks, which of the following could do that? a) System.out.println("hi there"); b) System.out.println(""hi there""); c) System.out.println("\"hi there"); d) System.out.println("\"hi there\""); e) none, it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output 14) If you want to store into the String name the value "George Bush", you would do which statement? a) String name = "George Bush"; b) String name = new String("George Bush"); c) String name = "George" + " " + "Bush"; d) Any of the above would work 15) Suppose that String name = "Frank Zappa". What will the instruction name.substring(2, 6) return? a) "ran" b) "rank" c) "rank " d) "ank Z" e) "rank Zappa" f) "rk" g) "ank " h) "ank" Free Form Questions 16) What is wrong with the following class definition? Fix all the syntax errors. Public Class Program \\ A problem program Public static voided main[strings( ) args] system.out.println('this program has syntax errors'); \* oh, my... *\ system.out.println('input a number'); \* lots of errors *\ x = scan.nextint( ); square = Math.pow(x); system.out.println('the square of the number is x');

17) The following program takes as inputs from the user (1) the cost per kilowatt-hour in cents as an integer and (2) the number of kilowatt-hours the appliance used in a year as an integer. Complete the program so that it computes and displays the energy cost of the appliance in dollars in a year. You do not need to format the output. public class EnergyCost public static void main(string[] args) Scanner scan = new Scanner (System.in); //Read in cost per kilowatt-hour and number of hours in a year System.out.println("Enter the cost per kilowatt-hour in cents for the applicance:"); int unitcost = scan.nextint(); System.out.println("Enter the number of kilowatt-hours in a year:"); int numofhours = scan.nextint(); //compute the energy cost //display output

18) The following program prompts the user to enter the number of minutes (e.g. 5 million). Complete the program so it computes and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days. Here is a sample run: Enter the number of minutes: 5000000 5000000 minutes is approximately 9 years and 187 days public class MinutesToDays public static void main(string[] args) Scanner sc = new Scanner (System.in); System.out.println("Enter the number of minutes:"); int minutes = sc.nextint(); //computes the years and days //display results

19) The following program reads a number between 1,000 and 999,999 from the user, where the user enters a comma in the input. Complete the program so it prints the number without a comma. Here is a sample input and output: Please enter an integer between 1,000 and 999,999: 34,953 Output: 34953 public class NumberInput public static void main(string[] args) // Read in a number as a string between 1,000 and 999,999 Scanner scan = new Scanner(System.in); System.out.println("Enter a number between 1,000 and 999,999"); String number = scan.next(); //compute the output //display the output