All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
computer science
starting out with java from control structures
Questions and Answers of
Starting Out With Java From Control Structures
What will the println statement in the following program segment display? int x = 5;System.out.println(x++);a. 5b. 6c. 0d. None of these
Write a program that asks the user for a positive nonzero integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user
What will the following program segments display?a) x = 2;y = x++;System.out.println(y);b) x = 2;System.out.println(x++);c) x = 2;System.out.println(--x);d) x = 8;y = x--;System.out.println(y);
Briefly describe the difference between the prefix and postfix modes used by the increment and decrement operators.
Write a while loop that lets the user enter a number. The number should be multiplied by 10, and the result stored in the variable product. The loop should iterate as long as product contains a value
Find the errors in the following code: 1. // This code contains ERRORS!// It adds two numbers entered by the user.int num1, num2;String input;char again;Scanner keyboard = new
What is wrong with the following switch statement? // This code has errors!!!switch (temp){ case temp < 0 : System.out.println("Temp is negative."); break; case temp =
Write an if statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10.
Explain what is meant by the phrase “conditionally executed.”
Write an if statement that assigns 0 to x when y is equal to 20.
Explain why a misplaced semicolon can cause an if statement to operate incorrectly.
Write an if statement that multiplies payRate by 1.5 if hours is greater than 40.
>, <, and == are __________.a. Relational operatorsb. Logical operatorsc. Conditional operatorsd. Ternary operators
The if statement is an example of a __________.a. Sequence structureb. Decision structurec. Pathway structured. Class structure
Using the following chart, write an if-else-if statement that assigns .10, .15, or .20 to commission, depending on the value in sales. Sales Up to $10,000 $10,000 to $15,000 Over
Write an if statement that assigns 100 to x when y is equal to 0.
Write a program that prompts the user to enter a number within the range of 1 through 10. The program should display the Roman numeral version of that number. If the number is outside the range of 1
This type of expression has a value of either true or false.a. Binary expressionb. Decision expressionc. Unconditional expressiond. Boolean expression
Write an if-else statement that assigns 0 to x when y is equal to 10. Otherwise, it should assign 1 to x.
Write a program that calculates and displays a person’s body mass index (BMI). The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or underweight for his
Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should
Why is it good advice to indent all the statements inside a set of braces?
Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 10000.
&&, ||, and ! are __________.a. Relational operatorsb. Logical operatorsc. Conditional operatorsd. Ternary operators
Write an if statement that sets the variable hours to 10 when the boolean flag variable minimum is equal to true.
What happens when you compare two String objects with the == operator?
Write an if statement that sets the variable fees to 50 if the boolean variable max is true.
This is an empty statement that does nothing.a. Missing statementb. Virtual statementc. Null statementd. Conditional statement
Write nested if statements that perform the following tests: If amount1 is greater than 10 and amount2 is less than 100, display the greater of the two.
Scientists measure an object’s mass in kilograms and its weight in Newtons. If you know the amount of mass that an object has, you can calculate its weight, in Newtons, with the following
Explain the purpose of a flag variable. Of what data type should a flag variable be?
To create a block of statements, you enclose the statements in these.a. Parentheses()b. Square brackets []c. Angled brackets <>d. Braces {}
Write an if statement that prints the message “The number is valid” if the variable grade is within the range 0 through 100.
Write a program that asks the user to enter a number of seconds.• There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should
What risk does a programmer take when not placing a trailing else at the end of an if-else-if statement?
This is a boolean variable that signals when some condition exists in the program.a. Flagb. Signalc. Sentineld. Siren
Write an if statement that prints the message “The number is valid” if the variable temperature is within the range −50 through 150.
A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Write a program that asks the user to enter the number of packages
Briefly describe how the && operator works.
Write an if statement that displays “Goodbye” if the variable myCharacter contains the character 'D'.
How does the character ‘A’ compare to the character ‘B’?a. ‘A’ is greater than ‘B’b. ‘A’ is less than ‘B’c. ‘A’ is equal to ‘B’d. You cannot compare characters
Write an if statement that prints the message “The number is not valid” if the variable hours is outside the range 0 through 80.
Briefly describe how the || operator works.
Write an if-else statement that assigns 20 to the variable y if the variable x is greater than 100. Otherwise, it should assign 0 to the variable y.
This is an if statement that appears inside another if statement.a. Nested if statementb. Tiered if statementc. Dislodged if statementd. Structured if statement
The Fast Freight Shipping Company charges the following rates: The shipping charges per 500 miles are not prorated. For example, if a 2-pound package is shipped 550 miles, the charges would be
Write an if-else statement that displays the String objects title1 and title2 in alphabetical order.
Why are the relational operators called “relational”?
Write an if-else statement that assigns 1 to x when y is equal to 100. Otherwise, it should assign 0 to x.
Write an if-else statement that assigns 0.10 to commission unless sales is greater than or equal to 50000.0, in which case it assigns 0.2 to commission.
An else clause always goes with __________.a. The closest previous if clause that doesn’t already have its own else clauseb. The closest if clausec. The if clause that is randomly selected by the
Convert the following if-else-if statement into a switch statement: if (choice == 1){ System.out.println("You selected 1.");}else if (choice == 2 || choice ==
Write a program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9
When does a constructor execute? What is its purpose?
Write an if-else statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10. Otherwise, it should assign –99 to the variable b and assign 0 to the
When determining whether a number is inside a range, it’s best to use this operator.a. &&b. !c. ||d. ? :
Match the conditional expression with the if-else statement that performs the same operation. a. q = x < y ? a + b : x * 2;b. q = x < y ? x * 2 : a + b;c. q = x < y ? 0 : 1;____ if (x
Write a program that asks for the names of three runners and the time, in minutes, it took each of them to finish a race. The program should display the names of the runners in the order that they
Write nested if statements that perform the following test: If amount1 is greater than 10 and amount2 is less than 100, display the greater of the two.
This determines whether two different String objects contain the same string.a. The == operatorb. The = operatorc. The equals methodd. The stringCompare method
Assume the double variable number contains the value 12345.6789. Write a statement that uses System.out.printf to display the number as 12345.7.
The following table shows the approximate speed of sound in air, water, and steel: Write a program that asks the user to enter “air”, “water”, or “steel”, and the distance that a
Write code that tests the variable x to determine whether it is greater than 0. If x is greater than 0, the code should test the variable y to determine whether it is less than 20. If y is less than
The conditional operator takes this many operands.a. Oneb. Twoc. Threed. Four
Assume the double variable number contains the value 12345.6789. Write a statement that uses System.out.printf to display the number as 12,345.68.
What will the following program display? public class CheckPoint{ public static void main(String[] args) { int funny = 7, serious = 15; funny = serious % 2; if (funny !=
This section of a switch statement is branched to if none of the case expressions match the switch expression.a. Elseb. Defaultc. Cased. Otherwise
Modify the program you wrote for Programming Challenge 13 so it also calculates and displays the amount of money Package A customers would save if they purchased Package B or C, and the amount of
You can use this method to display formatted output in a console window.a. Format.out.printlnb. Console.formatc. System.out.printfd. System.out.formatted
The following truth table shows various combinations of the values true and false connected by a logical operator. Complete the table by circling T or F to indicate whether the result of such a
A bank charges a base fee of $10 per month, plus the following check fees for a commercial checking account:$.10 each for less than 20 checks$.08 each for 20–39 checks$.06 each for 40–59
True or False: The = operator and the == operator perform the same operation.
Serendipity Booksellers has a book club that awards points to its customers based on the number of books purchased each month. The points are awarded as follows: • If a customer purchases 0
Assume the variables a = 2, b = 4, and c = 6. Circle the T or F for each of the following conditions to indicate whether it is true or false. 4 || b > 2 3 a ==4 6 1 != b && c != 3 a >= -1 || a
True or False: A conditionally executed statement should be indented one level from the if clause.
Write an if statement that displays the message "The number is valid" if the variable speed is within the range 0 through 200.
True or False: All lines in a conditionally executed block should be indented one level.
Write an if statement that displays the message "The number is not valid" if the variable speed is outside the range 0 through 200.
True or False: When an if statement is nested in the if clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is true.
Assume the variable name references a String object. Write an if statement that displays “Do I know you?” if the String object contains “Timothy”.
True or False: When an if statement is nested in the else clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is
Assume the variables name1 and name2 reference two different String objects, containing different strings. Write code that displays the strings referenced by these variables in alphabetical order.
True or False: The scope of a variable is limited to the block in which it is defined.
Rewrite the following if-else statements as statements that use the conditional operator. a) if (x > y) z = 1;else z = 20;b) if (temp > 45) population = base *
Complete the following program skeleton by writing a switch statement that displays “one” if the user has entered 1, “two” if the user has entered 2, and “three” if the user has entered
Rewrite the following if-else-if statement as a switch statement. if (selection == 'A') System.out.println("You selected A.");else if (selection == 'B') System.out.println("You
Explain why you cannot convert the following if-else-if statement into a switch statement. if (temp == 100) x = 0;else if (population > 1000) x = 1;else if (rate < .1) x =
Assume the following variable declaration exists in a program: Double number = 1234567.456;Write a statement that uses System.out.printf to display the value of the number variable formatted
Assume the following variable declaration exists in a program: Double number = 123.456;Write a statement that uses System.out.printf to display the value of the number variable padded with
Assume the following variable declaration exists in a program: Int number = 123456; Write a statement that uses System.out.printf to display the value of the number variable in a field that
Assume the following variable declaration exists in a program:Double number = 123456.789;Write a statement that uses System.out.printf to display the value of the number variable left-justified, with
Assume the following declaration exists in a program: String name = "James"; Write a statement that uses System.out.printf to display33 the value of name in a field that is 20 spaces wide.
Assume the int variable number contains the value 1234567. Write a statement that uses System.out.printf to display the number as 1,234,567.
These characters mark the beginning of a single-line comment.a. //b. /*c. */d. /**
Write pseudocode algorithms for the programs described as follows:1. Available CreditA program that calculates a customer’s available credit should ask the user for the following:• The
Both main memory and secondary storage are types of memory. Describe the difference between the two.
This assignment will help you get acquainted with your Java development software. Here is the Java program you will enter:// This is my first Java program.public class MyFirstProgram{public static
This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some outcome or resultant information.a. Memoryb. CPUc. Secondary storaged.
Why is the computer used by so many different people, in so many different professions?
The following are programs expressed as English statements. What would each display on the screen if they were actual programs?1. The variable x starts with the value 0.The variable y starts with the
Showing 1000 - 1100
of 1252
1
2
3
4
5
6
7
8
9
10
11
12
13