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
Write a program that accepts as input a sentence in which all of the words are run together, but the first character of each word is uppercase. Convert the sentence to a string in which the words are
This String method breaks a string into tokens.a. Breakb. Tokenizec. GetTokensd. Split
What is the difference between the getChars and toCharArray methods?
The character that separates tokens in a string is known as a __________.a. Separatorb. Tokenizerc. Delimiterd. Terminator
The + operator, when used with strings, performs the same operation as what String method?
To delete a specific character in a StringBuilder object, use this method.a. DeleteCharAtb. RemoveCharAtc. RemoveChard. Expunge
What is the difference between the getChars and substring methods?
The file SalesData.txt, in this chapter’s source code folder, contains the dollar amount of sales that a retail store made each day for a number of weeks. Each line in the file contains seven
Write code that displays the contents of the int variable i in binary, hexadecimal, and octal.
To change the value of a specific character in a StringBuilder object, use this method.a. ChangeCharAtb. SetCharAtc. SetChard. Change
This is one of the methods that are common to both the String and StringBuilder classes.a. Appendb. Insertc. Deleted. Length
Write a program that displays a simulated paycheck. The program should ask the user to enter the date, the payee’s name, and the amount of the check. It should then display a simulated check with
Look at the following declaration: String cafeName = "Broadway Cafe";String str;Which of the following methods would you use to make str reference the string
Look at the following string: "Cookies>milk>fudge:cake:ice cream"Write code using the String class’s split method that can be used to extract the following tokens from the string:
If you do not pass an argument to the StringBuilder constructor, the object will have enough memory to store this many characters. a. 16b. 1c. 256d. Unlimited
Write a program that asks the user to enter a series of numbers separated by commas. Here is an example of valid input: 7,9,10,2,18,6 The program should calculate and display the sum of all
Write a method that accepts a StringBuilder object as an argument and converts all occurrences of the lowercase letter ‘t’ in the object to uppercase.
Write a program that has two parallel arrays of String objects. One of the arrays should hold people’s names and the other should hold their phone numbers. Here are example contents of both
The String class has several overloaded versions of a method that accepts a value of any primitive data type as its argument and returns a string representation of the value. The name of the method
Write a method that accepts a reference to a String object as an argument and returns true if the argument ends with the substring “ger”. Otherwise, the method should return false.
This String class method performs the same operation as the + operator when used on strings.a. Addb. Joinc. Concatd. Plus
Write a loop that counts the number of uppercase characters that appear in the String object str.
Write a method that accepts a reference to a String object as an argument and returns true if the argument ends with the substring “.com”. Otherwise, the method should return false.
The substring, getChars, and toCharArray methods are members of this class.a. Stringb. Floatc. Characterd. Wrapper
Imagine you are developing a software package for Amazon.com that requires users to enter their own passwords. Your software requires that users’ passwords meet the following criteria: • The
How can you determine the minimum and maximum values that may be stored in a variable of a given data type?
Write a loop that counts the number of lowercase characters that appear in the String object str.
The indexOf and lastIndexOf methods are members of this class.a. Stringb. Integerc. Characterd. Wrapper
Write a loop that asks the user, “Do you want to repeat the program or quit? (R/Q)”. The loop should repeat until the user has entered an R or Q (either upper case or lowercase).
Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the
Each of the numeric wrapper classes has a static toString method. What do these methods do?
Write a loop that counts the number of digits that appear in the String object str.
The startsWith, endsWith, and regionMatches methods are members of this class.a. Stringb. Charc. Characterd. Wrapper
What is the output of the following statement? System.out.println(Character.toUpperCase(Character.toLowerCase('A')));
Write a method that accepts a String object as an argument and returns a copy of the string with the first character of each sentence capitalized. For instance, if the argument is “hello. my name
A program reads a string as input from the user for the purpose of tokenizing it. Why is it a good idea to trim the string before tokenizing it?
Write a loop that counts the number of space characters that appear in the String object str.
This method converts a character to uppercase.a. MakeUpperCaseb. ToUpperCasec. IsUpperCased. UpperCase
Write an if statement that displays the word “digit” if the char variable ch contains a numeric digit. Otherwise, it should display “Not a digit.”
Write a method that accepts a String object as an argument and returns the number of words it contains. For instance, if the argument is “Four score and seven years ago” the method should return
Why should you use StringBuilder objects instead of String objects in a program that makes lots of changes to strings?
The following if statement determines whether choice is equal to ‘Y’ or ‘y’: If (choice == 'Y' || choice == 'y')Rewrite this statement so it makes only one comparison and does not use
The isDigit, isLetter, and isLetterOrDigit methods are members of this class.a. Stringb. Charc. Characterd. StringBuilder
Write a statement that converts the contents of the char variable big to lowercase. The converted value should be assigned to the variable little.
Write a method that accepts a String object as an argument and displays its contents backward. For instance, if the string argument is “gravity” the method should display -“ytivarg”.
Assume that the following enumerated data type has been declared: Enum Creatures{ HOBBIT, ELF, DRAGON }What will the following code display? System.out.println(Creatures.HOBBIT + " " +
This array field holds the number of elements that the array has.a. Sizeb. Elementsc. Lengthd. Width
The following statement creates a BankAccount array:BankAccount[] acc = new BankAccount[10]; Is it okay or not okay to execute the following
The variable names references an integer array with 20 elements. Write a for loop that prints each element of the array.
What is the difference between a size declarator and a subscript?
Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should have methods that return the following:• The total rainfall for the year•
Write statements that create the following arrays:a) A 100-element int array referenced by the variable employeeNumbers.b) A 25-element double array referenced by the variable payRates.c) A
In an array declaration, this indicates the number of elements that the array will have. a. Subscriptb. Size declaratorc. Element sumd. Reference variable
Look at the following array definition: Int[] values = { 4, 7, 6, 8, 2 };What does each of the following code segments display? System.out.println (values [4]); X = values [2] +
The variables numberArray1 and numberArray2 reference arrays that each have 100 elements. Write code that copies the values in numberArray1 to numberArray2.
Create a class with a method that accepts a charge account number as its argument. The method should determine whether the number is valid by comparing it to the following list of valid charge
Look at the following array definition: Int[] values = new int[10];a. How many elements does the array have?b. What is the subscript of the first element in the array?c. What is the subscript of
What’s wrong with the following array declarations? Int[] readings = new int[-1];Double[] measurements = new double[4.5];
Each element of an array is accessed by a number known as a(n) __________. a. Subscriptb. Size declaratorc. Addressd. Specifier
What would the valid subscript values be in a four-element array of doubles?
The first subscript in an array is always ___________.a. 1b. 0c. -1d. 1 less than the number of elements
In a program you need to store the populations of 12 countries.a. Define two arrays that may be used in parallel to store the names of the countries and their populations.b. Write a loop that uses
How do you define an array without providing a size declarator?
What is the difference between an array’s size declarator and a subscript?
The last subscript in an array is always __________.a. 100b. 0c. -1d. 1 less than the number of elements
In a program you need to store the identification numbers of ten employees (as int values) and their weekly gross pay (as double values).a. Define two arrays that may be used in parallel to store the
In a program, write a method that accepts two arguments: an array and a number n. Assume that the array contains integers. The method should display all of the numbers in the array that are greater
Array bounds checking happens __________.a. When the program is compiledb. When the program is savedc. When the program runsd. When the program is loaded into memory
Declare a two-dimensional int array named grades. It should have 30 rows and 10 columns.
How do you establish an array without providing a size declarator?
What happens in Java when a program tries to use a subscript that is out of bounds?
Find the Error throughout each step. 1. Int[] collection = new int[-20];2. Int[] hours = 8, 12, 16;3. Int[] table = new int[10];for (int x = 1; x <= 10; x++){ table[x] = 99;}4. String[] names
Write a program that lets the user enter four quarterly sales figures for six divisions of a company. The figures should be stored in a two-dimensional array. Once the figures are entered, the
Assuming that array1 and array2 are both array reference variables, why is it not possible to assign the contents of the array referenced by array2 to the array referenced by array1 with the
This search algorithm steps through an array, comparing each item with the search value.a. Binary searchb. Sequential searchc. Selection searchd. Iterative search
Look at the following array declaration: Int[][] numberArray = new int[9][11];a. Write a statement that assigns 145 to the first column of the first row of this array.b. Write a statement that
A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test
If a sequential search method is searching for a value that is stored in the last element of a 10,000-element array, how many elements will the search code have to read to locate the value?
This search algorithm repeatedly divides the portion of an array being searched in half.a. Binary searchb. Sequential searchc. Selection searchd. Iterative search
The values variable references a two-dimensional double array with 10 rows and 20 columns. Write code that sums all the elements in the array and stores the sum in the variable total.
Look at the following array definition: Double[][] sales = new double[8][10];a. How many rows does the array have?b. How many columns does the array have?c. How many elements does the array
Look at the following statements: Int[] numbers1 = { 1, 3, 6, 9 };Int[] numbers2 = { 2, 4, 6, 8 };Int result;Write a statement that multiplies element 0 of the numbers1 array by element 3 of the
This is the typical number of comparisons performed by the sequential search on an array of N elements (assuming the search values are consistently found).a. 2Nb. Nc. N2d. N/2
An application uses a two-dimensional array declared as follows:Int[][] days = new int[29][5]; a. Write code that sums each row in the array and displays the results.b. Write code that sums each
A program uses a variable named array that references an array of integers. You do not know the number of elements in the array. Write a for loop that stores −1 in each element of the array.
When initializing a two-dimensional array, you enclose each row’s initialization list in ___________.a. Bracesb. Parenthesesc. Bracketsd. Quotation marks
Write code that creates an ArrayList that can hold String objects. Add the names of three cars to the ArrayList, and then display the contents of the ArrayList.
Write a program with an array that is initialized with test data. Use any primitive data type of your choice. The program should also have the following methods: • GetTotal. This method should
A program has the following declaration: Double[] values;Write code that asks the user for the size of the array and then creates an array of the specified size, referenced by the values
To insert an item at a specific location in an ArrayList object, you use this method.a. Storeb. Insertc. Addd. Get
Write a class with a constructor that accepts a file name as its argument. Assume the file contains a series of numbers, each written on a separate line. The class should read the contents of the
To delete an item from an ArrayList object, you use this method.a. Removeb. Deletec. Erased. Get
Look at the following method header: Public static void myMethod(double[] array)Here is an array declaration:Double[] numbers = new double[100];Write a statement that passes the numbers array to
To determine the number of items stored in an ArrayList object, you use this method.a. Sizeb. Capacityc. Itemsd. Length
Write a method named zero, which accepts an int array as an argument and stores the value 0 in each element.
True or False: Java does not allow a statement to use a subscript that is outside the range of valid subscripts for an array.
True or False: An array’s sitze declarator can be a negative integer expression.
a) Write a statement that declares a String array initialized with the following strings: “Mercury”, “Venus”, “Earth”, and “Mars”.b) Write a loop that displays the contents of each
True or False: Both of the following declarations are legal and equivalent: Int[] numbers;Int numbers[];
True or False: The subscript of the last element in a single-dimensional array is one less than the total number of elements in the array.
Showing 600 - 700
of 1252
1
2
3
4
5
6
7
8
9
10
11
12
13