1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gnesinka [82]
3 years ago
8

What will be printed after the following code is executed? String str = "abc456"; int m = 3; while ( m =< str.length() - 1) {

if (Character.isDigit(str.charAt(m))) System.out.print(Character.toUpperCase(str.charAt(m))); m++; }
Computers and Technology
2 answers:
Natasha_Volkova [10]3 years ago
5 0

Answer:

456

will be printed after execution of this code.

Explanation:

  • while loop will run till the condition is true that given value for m is greater than or equal to (string length -1) or say 5
  • As m = 3 is given so first time the loop will run it goes to if statement which uses m value as a index to pull character from str and checks if it is a digit or alphabet. It will proceed if the character is a digit.
  • As at index 3 (starting from 0) the character is 4, so it will proceed to next statement which prints the extracted character on the screen after converting it into Upper case.
  • As digits are not affected so the digit 4 will be printed.
  • m will be increased by 1 making m = 4.
  • Now the while condition is still true so is statement will return character at index 4 that is 5.
  • It will be sent to next statement but toUpperCase function does not changes digits so 5 will be printed.
  • Increment in m makes m = 5
  • While statement is still true so 5th character from string is extracted that is 6. As it is a digit so moving to next statement will not change the character because toUpperCase does not apply on digits.
  • Now when m is incremented it becomes 6 which will give false to the while condition so the loop will be terminated.
  • Now the answer printed on to screen in 456.  

I hope it will help you!

IRINA_888 [86]3 years ago
4 0

Answer:

456 will be printed

Explanation:

The following shows a well formatted equivalent of the code snippet:

String str = "abc456";    //Line 1

int m = 3;        //Line 2

while (m <= str.length() - 1) {  //Line 3

    if (Character.isDigit(str.charAt(m)))  //Line 4

 System.out.print(Character.toUpperCase(str.charAt(m)));    //Line 5

  m++;                   //Line 6

 }   //Line 7

Line 1 shows the declaration and initialization of a String variable str.

Line 2 shows the declaration and initialization of an integer variable m.

Lines 3 through 7 show a while loop.

The loop starts at m = 3, increments m by one at every cycle, and ends at m = 5 which is one less than the length of the String str. i.e 6 - 1 = 5

At each cycle, the loop checks if the character at index m of the str is a digit. If it is a digit, it is converted to an uppercase letter(which is irrelevant) and then printed to the console.

At m=3, the character is a digit which is 4

At m=4, the character is a digit which is 5

At m=5, the character is a digit which is 6

Therefore, 456 is printed to the console.

Note: I have assumed that the statement in the while loop of the code you wrote was a typo and as such I have changed it to the correct syntax. That is, I have changed ;

while(m =< str.length( ) - 1) to

while(m <= str.length( ) - 1) for the code to perform the intended function.

Otherwise, if it is the case that it wasn't a typo, then the code will neither compile nor run as it contains a syntax error.

Hope this helps!

You might be interested in
A general-use dimmer switch is required to be counted as ? where installed in a single-gang box on a circuit wired with 12 awg c
aleksandrvk [35]

Answer:

2 conductors.

Explanation:

A dimmer switch is an electrical switching or control device used to control the power or voltage to a compatible dimmer bulb.

It reduces the ambience if light bulbs by uniformly increasing the resistance of the switch when the knob is rotated to a lesser point. It is a circuit breaker as two conductors are connected to its terminals and a variable voltage resistor determines the flow of current between them.

3 0
4 years ago
What is the value of the result after the following statement is executed? int result = 2 + 3 + 4 ;
kow [346]

2 + 3 + 4 = 9 so the value of result is also 9

8 0
3 years ago
What medical equipment do they have in Jr. high, To help save peoples lives?
lawyer [7]

Vital signs monitors, Electronic Medical Records (EMR), and Medication Management Systems.

5 0
3 years ago
python If the checksum is 10, the last digit is denoted as X according to the ISBN-10 convention. Write a program that prompts t
aksik [14]

Answer:

PYTHON CODE:

str = input("Enter the first 9 digits of an ISBN-10 as a string : ") # user input

i = 1

checksum = 0 # for total sum

while i < 10:

c = int(str[i - 1]) # getting every digit of the ISBN

c = c * i

checksum += c

i=i+1

checksum=checksum % 11 # getting the last digit of ISBN

ch=checksum

if checksum==10: # if the last digit is 10 then change it to X

ch="X"

print("The Complete 10-Digit ISBN is : ",end="")

print(str,end="") # displaying the 9 digit of ISBN

print(ch) # appending the last digit of ISBN

Explanation:

3 0
3 years ago
Isabel has an interesting way of summing up the values in a sequence A ofn integers, where n is a power of two. She creates a ne
olganol [36]

Answer:

Running time of algorithm is O(n).

Explanation:

n is power of 2

n =2,4,8,16,32,...................................

A is an array having n elements

B is an array of size 0 to (n/2)-1

if n=4 B then (4/2)-1 =1 So B has size 2

for(i=0;i<=(n/2)-1;++)

{

B[i]=A[2i]+A[2i+1];

}

This for loop will run n/2 times so complexity in terms of Big Oh is O(n/2) =O(n)

Running time of algorithm is O(n).

6 0
3 years ago
Other questions:
  • How many times does the following loop execute? double d; Random generator = new Random(); double x = generator.nextDouble() * 1
    14·1 answer
  • 10^4+10-2=<br>10^4+10-2=
    12·2 answers
  • What is ambient sound, and what is its purpose in film? When can it be a drawback ?
    7·1 answer
  • A/an ________is a device used to protect computers against surges and spikes in power.
    14·1 answer
  • Why do you think it is important to consider ethical considerations when reviewing technology and assessing the impact of partic
    9·1 answer
  • Write a Unix (Linux) find-like command (myFind) in Python3 where the function will return the full paths of all the files contai
    9·1 answer
  • What would be the desired output of the home-security system
    8·1 answer
  • How are satellite radio, Internet radio, and podcasting different?
    11·1 answer
  • High-level languages must be translated into machine language before they can be executed. _________________________
    10·1 answer
  • What is the number base of the binary number system?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!