CSCI 2350 Programming and Data Structures
If you wanted to give $0.78 in change, there are a number of ways you could do this. Make sure to answer in integers. 1. The number of dollars is calculated by 78/100 = __ and the number of cents is calculated by 78%100 = __ . 2. The number of quarters is calculated by 78/25 = __ and the number of cents is calculated by 78%25 = __ . 3. The number of dimes is calculated by 78/10 = __ and the number of cents is calculated by 78%10 = __ . 4. The number of nickels is calculated by 78/5 = __ and the number of cents is calculated by 78%15 = __ .
0, 78 3, 3 7, 8 15, 3
What range of integers do the following lines of code produce? int guess1 = (int)(Math.random() *10); // from __ to __ int guess2 = (int)(Math.random() *10) + 1; // from __ to __ int guess3 = (int)(Math.random() *50); // from __ to __ int guess4 = (int)(Math.random() *11) + 50; // from __ to __
0, 9 1, 10 0, 49 50, 60
Correct the following errors: 1. double radius = 5; double area = 3.14 * Math.pow(Radius, 2) 2. int diameter = 9; double radius = diameter / 2 3. Scanner input = new Scanner(System.in); System.out.print("Enter a number of items:"); int numItems1 = input.nextInt(); Scanner input = new Scanner(System.in); System.out.print("Enter the price:"); double cost1 = input.nextDouble();
1. Radius should be lowercase 2. 2 should be 2.0 3. remove the second Scanner input = new Scanner(System.in);
The following is a sequence of lines in a program. After each line below, determine the value assigned to the variable: int r = 2; // r = __ double area = 5.0; // area = r = r + 1; // r = __ double circumference = 6.28 * r; //circumference = __ 5 = r; // r = __
2 5.0 3 18.84 error
Match the line of code of division or remainder with it's value. System.out.println(5.0/2.0); __ System.out.println(5/2); __ System.out.println(4.0/2); __ System.out.println(6/2.0); __ System.out.println(5%2); __ System.out.println(5.0%2.0); __
2.5 2 2.0 3.0 1 1.0
cost is 1293.42 discountRate is 0.20 discount is cost times discountRate discount = cost * discountRate; __ discount = cost * discountRate * 100; __ discount = (int) cost * discountRate * 100; __ discount = (int) (cost * discountRate * 100); __ discount = (int) (cost * discountRate * 100) / 100; __ discount = (int) (cost * discountRate * 100) / 100.0; __ discount = (int) (cost * discountRate * 10) / 10.0; __
258.684 25868.4 25860 25868 258 258.68 258.6
Which line is a statement? 1 public class Welcome { 2 public static void main(string[] args) { 3 //Display message Welcome to Java on the console 4 System.out.println("Welcome to Java"); } }
4
What is the name of this file? public class Exercise01_02 { public static void main(String[] args) { //Display message Welcome to Java five times on the console System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); } }
Exercise01_02
What is wrong with the naming of this file? public class exercise01_02 { public static void main(String[] args) { //Display message Welcome to Java five times on the console System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); } }
It is not capitalized.
Order the stages of the software development process. System Analysis Testing Requirement Specifications Maintenance System Design Deployment Implementation
Requirement Specifications System Analysis System Design Implementation Testing Deployment Maintenance
Which word is not capitalized but should be? public class Exercise01_02 { public static void main(string[] args) { //Display message Welcome to Java five times on the console System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); System.out.println("Welcome to Java"); } }
String
What flowchart is this?
two-way if statement
Select the missing punctuation marks. public class Welcome __ public static void main __ String __ __ args __ __ System.out.println __ __ Welcome to Java __ __ __ __ __
{ ( [ ] ) { ( " " ) ; } }
What are the special characters used for each description? Denote a block to enclose statements. Used with methods. Denote an array. Precede a comment line. Enclose a string. Mark the end of a statement.
{ } ( ) [ ] / / " " ;
What words below are keywords? public class Welcome { public static void main(string[] args) { //Display message Welcome to Java on the console System.out.println("Welcome to Java"); } }
public static void class
Truth Table for Operator ! p --> !p false --> __ true --> __
true false
Write the code to determine if an inputted number is even or odd in order.
import java.util.Scanner; public class EvenOdd { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a number: "); int number = input.nextInt(); if (number % 2 == 0) System.out.println(number + " is even."); else System.out.println(number + " is odd."); } }
Put the code for swap in order: second = temp; int temp = first; first = second;
int temp = first; first = second; second = temp;
What flowchart is this?
multi-way if statement
Truth Table for Operator && p1 p2 --> p1 && p2 true true --> __ true false --> __ false true --> __ false false --> __
true false false false
Match the code to the question it answers. Is the integer even? Is the integer odd? What day of the week will it be? How many weeks will it be?
n % 2 = 0 n % 2 = 1 d % 7 d / 7
What flowchart is this?
one-way if statement
Truth Table for Operator || p1 p2 --> p1 || p2 true true --> __ true false --> __ false true --> __ false false --> __
true true true false
Order the following data types from least to greatest by storage size. double long byte int short float
byte short int long float double
Identifiers can be which of the following: contain letters contain digits contain underscores (_) contain dollar signs ($) can start with a letter can start with a digit can start with an underscore (_) can start with a dollar sign ($) can be a reserved word
contain letters contain digits contain underscores (_) contain dollar signs ($) can start with a letter can start with an underscore (_) can start with a dollar sign ($)
Truth Table for Operator ^ p1 p2 --> p1 ^ p2 true true --> __ true false --> __ false true --> __ false false --> __
false true true false
Order the following program correctly so that it creates a Scanner object, prompts the user to enter a radius, computes area, and displays the result. public class ComputeArea { radius + " is " + area); double area = radius *(asterisk) radius *(asterisk) 3.14159; System.out.print("Enter a number for radius: "); import java.util.Scanner; public static void main(String[] args) { } } System.out.println("The area for the circle of radius " + Scanner input = new Scanner(System.in); double radius = input.nextDouble();
import java.util.Scanner; public class ComputeArea { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a number for radius: "); double radius = input.nextDouble(); double area = radius *(asterisk) radius *(asterisk) 3.14159; System.out.println("The area for the circle of radius " + radius + " is " + area); } }
