70.3k views
5 votes
Unlimited tries Assume a char variable named big has been declared and assigned a value. Also assume a char variable named little has been declared. Write a statement that converts the contents of the big variable to lowercase. Assign the converted value to the variable little. The following if statement is incomplete, but it should display the word "digit" if the char variable ch contains a numeric digit. Otherwise, the statement should display "Not a digit." What Boolean expression would you write inside the parentheses of the if statement? if(System.out.println("digit"); ( lˉelse System.out.println( "Not a digit"); The following code uses a for loop to count the number of uppercase characters in the string object str. What Boolean expression would you write inside the parentheses of the if statement to complete the code? int total=0for (inti=0;i

User Ng Sharma
by
8.9k points

2 Answers

1 vote

Final answer:

To convert the contents of the big variable to lowercase and assign the converted value to the little variable, use the toLowerCase() method. Determine if a char variable contains a numeric digit using Character.isDigit(). Count the number of uppercase characters in a String object using Character.isUpperCase().

Step-by-step explanation:

To convert the contents of the big variable to lowercase and assign the converted value to the little variable, you can use the toLowerCase() method in Java. Here's the statement:

little = big.toLowerCase();

To determine if a char variable ch contains a numeric digit or not, you can use the Character.isDigit() method. Here's the Boolean expression for the if statement:

if (Character.isDigit(ch)) {
System.out.println("digit");
} else {
System.out.println("Not a digit");
}

To count the number of uppercase characters in a String object str, you can use a for loop and check each character using the Character.isUpperCase() method. Here's the Boolean expression for the if statement:

if (Character.isUpperCase(str.charAt(i))) {
total++;
}
User Ehxor
by
9.0k points
2 votes

Convert the contents of the big variable to lowercase and assign it to the variable little: char little = Character.toLowerCase(big);

Complete the if statement to display "digit" if the char variable ch contains a numeric digit; otherwise, display "Not a digit." The Boolean expression inside the parentheses should be:

if (Character.isDigit(ch)) {

System.out.println("digit");

} else {

System.out.println("Not a digit");

}

Complete the code that uses a for loop to count the number of uppercase characters in the string object str. The Boolean expression inside the parentheses should be:

int total = 0;

for (int i = 0; i < str.length(); i++) {

if (Character.isUpperCase(str.charAt(i))) {

total++;

}

}

User Jonathan Allen
by
7.7k points