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
Which of the following is true of how packets are sent through the Internet?
astra-53 [7]

Answer:

It is A: Packet metadata is used to route and reassemble information travelling  through the internet.

Explanation:

Step 1: The Internet works by chopping data into chunks called packets. Each packet then moves through the network in a series of hops. Each packet hops to a local Internet service provider (ISP), a company that offers access to the network -- usually for a fee

Step 2: Entering the network

Each packet hops to a local Internet service provider (ISP), a company that offers access to the network -- usually for a fee.

Step 3: Taking flight

The next hop delivers the packet to a long-haul provider, one of the airlines of cyberspace that quickly carrying data across the world.

Step 4: BGP

These providers use the Border Gateway Protocol to find a route across the many individual networks that together form the Internet.

Step 5: Finding a route

This journey often takes several more hops, which are plotted out one by one as the data packet moves across the Internet.

Step 6: Bad information

For the system to work properly, the BGP information shared among routers cannot contain lies or errors that might cause a packet to go off track – or get lost altogether.

Last step: Arrival

The final hop takes a packet to the recipient, which reassembles all of the packets into a coherent message. A separate message goes back through the network confirming successful delivery.

8 0
4 years ago
Read 2 more answers
Brian needs to assign a macro to a button on the ribbon. Where should he go to achieve this goal?
8_murik_8 [283]

Answer: A. Record Macro dialog box.

Explanation:

3 0
4 years ago
Read 2 more answers
Which of these utility tools would you least expect a support agent to find useful to increase security for end users?
tia_tia [17]

Answer:

b. Network performance monitor

Explanation:

A utility tool can be defined as a software application or program designed to add more functionality to a computer system, as well as to improve its performance efficiently. Some examples of commonly used utility tools in computer are file and folder backup tools, file management, antivirus, hard disk diagnostics, registry cleaner, network performance monitor, screensavers etc.

In the context of increasing security for the end users, the most important utility tools are;

1. Antivirus utility: to scan, detect, remove and prevent computer viruses such as Malware, Trojan horses, keyloggers, botnets, adwares etc.

2. Rootkit utility: it can be used to detect and remove any rootkit program that is hidden in a computer.

3. Spyware utility: this is used to detect, remove and prevent malicious adware that are found in software applications.

<em>However, a network performance monitor is a utility tool that would be found to least support an agent in increasing security for end users because it is a utility tool that is primarily used to monitor network traffic and amount of data usage. </em>

7 0
3 years ago
Emily has to create an audio-visual presentation on animated movies. Which input device will she be LEAST likely to use while cr
Slav-nsk [51]
A joystick is less likely to be used while creating this presentation. Obviously, If your intention is to create an audio-visual presentation on animated movies, a computer should be used. With a computer, comes a keyboard, a mouse and a microphone as well.

A Joystick is used to control video games and play simulator games. Therefore, I do not see the need of using a joystick in this situation.

6 0
3 years ago
Enter a formula in cell C13 to look up the registration fee for the first vehicle. Use the vehicle type in cell C4 as the Lookup
UNO [17]

The formula that depicts the registration fee on the computer is Formula at C13 : =VLOOKUP(C4,Data!$B$10:$C$17,2,0)

<h3>How to illustrate the information?</h3>

A computer program is a sequence or set of instructions in a programming language for a computer to execute.

Computer programs are one component of software, which also includes documentation and other intangible components. A computer program in its human-readable form is called source code

In this case, enter a formula in cell C13 to look up the registration fee for the first vehicle.

Then, one can use the vehicle type in cell C4 as the Lookup_value argument and then use the RegistrationFees named range as the Table_array argument.

Learn more about computer on:

brainly.com/question/24540334

#SPJ1

7 0
2 years ago
Other questions:
  • A looping construct that continues to repeat until the expression becomes false is
    5·2 answers
  • This operating system was used by individual computers an required users to type commands
    10·1 answer
  • A virtual private network (VPN) is used to securely connect to another network over a insecure network.
    9·2 answers
  • Ar count = 10;
    13·1 answer
  • Design an algorithm for finding all the factors of a positive integer. For example, in the case of the integer 12, your algorith
    8·1 answer
  • The data type of 17.3 should be ________________.
    12·2 answers
  • Define and explain the two different methods by which a file can be compressed. Briefly describe one pro and one con for both ty
    13·1 answer
  • How to write the algorithm to calculate the square of five numbers
    14·2 answers
  • 23. Convert the following to Megabytes<br> a) 2GB<br> b) 2056 Bytes-
    8·2 answers
  • Hellpppppppppppppppp
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!