answer.
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
NikAS [45]
1 year ago
14

Write a method that takes three numerical String values and sums their values.

Computers and Technology
2 answers:
anyanavicka [17]1 year ago
6 0

Answer:

Is in the provided screenshot!

Explanation:

All we need to do is use the built in function "parseInt" to turn a String into an Integer, then we can just add these and return it from the function!

I've also added some basic exception handling - if any one of the numbers aren't written in correctly then the program will just return '-1' instead of crashing.

Sphinxa [80]1 year ago
4 0

Answer:

<u>Algorithm</u>:

  1. Take a int variable c=0.
  2. Run the loop from 0 to String length.
  3. Get the each index value using charAt() method which will return the char value.
  4. Convert that char into int by typecasting or any other way.
  5. Now check that ASCII fall into the range of 48-57 for 0-9 int number.
  6. If it matches then first convert that number into integer using Integer.parseInt().
  7. Then add with the c and store to the same variable i.e c.
  8. Repeat from 3-7 till the end of the loop.
  9. At the end of loop , Print c outside the loop.

Explanation:

// Java program to calculate sum of all numbers present  

// in a string containing alphanumeric characters  

class GFG  

{  

   // Function to calculate sum of all numbers present  

   // in a string containing alphanumeric characters  

   static int findSum(String str)  

   {  

       // A temporary string  

       String temp = "";  

       // holds sum of all numbers present in the string  

       int sum = 0;  

       // read each character in input string  

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

       {  

           char ch = str.charAt(i);  

           // if current character is a digit  

           if (Character.isDigit(ch))  

               temp += ch;  

           // if current character is an alphabet  

           else

           {  

               // increment sum by number found earlier  

               // (if any)  

               sum += Integer.parseInt(temp);  

               // reset temporary string to empty  

               temp = "0";  

           }  

       }  

       // atoi(temp.c_str()) takes care of trailing  

       // numbers  

       return sum + Integer.parseInt(temp);  

   }    

   // Driver code  

   public static void main (String[] args)  

   {      

       // input alphanumeric string  

       String str = "1abc5yz7";  

       System.out.println(findSum(str));  

   }  

}  

You might be interested in
c++ You are given an array A representing heights of students. All the students are asked to stand in rows. The students arrive
Lilit [14]

The below code will help you to solve the given problem and you can execute and cross verify with sample input and output.

#include<stdio.h>

#include<string.h>

 int* uniqueValue(int input1,int input2[])

 {

   int left, current;

   static int arr[4] = {0};

   int i      = 0;

     for(i=0;i<input1;i++)

      {

         current = input2[i];

         left    = 0;

         if(current > 0)

         left    = arr[(current-1)];

      if(left == 0 && arr[current] == 0)

       {

       arr[current] = input1-current;

       }

       else

   {

       for(int j=(i+1);j<input1;j++)

       {

           if(arr[j] == 0)

           {

               left = arr[(j-1)];

               arr[j] = left - 1;

           }

       }

   }

}

return arr;

}

4 0
2 years ago
What elements of SANS 20 you could leverage to reduce the TCP/IP vulnerabilities of your workstation
Vlada [557]

Answer:

- limitation and control of network ports, protocols and services.

- Continuous vulnerability assessment and remediation.

Explanation:

The TCP or transmission control protocol is a layer 4 protocol (transport), that reliably transports packets in sequential segments to an application in the destination computer, using the ip address and the port number of the application.

The ICMP sent during the TCP/ip activities, can render the network vulnerable to attacks. limitation and control of the network ports, protocols and services and continuous assessment would mitigate the vulnerability of the TCP/ip model.

5 0
1 year ago
Object-oriented development could potentially reduce the time and cost of writing software because: Group of answer choices a) i
spayn [35]

Answer:

b) objects are resuable

Explanation:

In OOP there's code reuse where a method or any other body of code is defined once and called or reused severally.

3 0
2 years ago
Which of the following is a job that does not lend itself to telecommuting?
jonny [76]

Answer:

a car salesman who demonstrates the features of a new model of car

Explanation:

Telecommuting can be defined as the process or making use of a telephone, email, or the internet to achieve your daily work. An attorney that spends most of her time researching on the computer is making use of an internet to do her work and hence telecommuting is employed. A copywriter for an advertising firm also makes use of email in the process of write copying and hence telecommuting is employed. A telemarketer uses the telephone and a product support who handles queries sent by customers also uses the internet and emails and telephones and hence they all use telecommuting. Demonstrating the feature of a new car does not use require the use of a telephone, email, or the internet.

8 0
1 year ago
How would you categorize the software that runs on mobile devices? Break down these apps into at least three basic categories an
I am Lyosha [343]

Mobile software is an App that can be downloaded to a mobile device and used to execute specific tasks. Once the app is initiated, it runs inside the operating system until it is been closed by the user. These are small, individual software units which can work as a browser, game, shopping app, calculator and more.


There are mainly 3 types of mobile apps:

Native applications, Hybrid applications, and Web applications.


Native Applications:

Native applications are developed to be used on a particular platform or device. They exist on the device and are accessed through icons on the device. Native apps are written for specific Operating System, which means a separate source code is written for each OS, such as iOS, Android, Linux, and Windows, this means, a native Android software will not work on a windows platform, because the Windows platform does not have the source code to operate the software, however, the advantages of native applications is that they can take the full advantage all features in the devices’


Web Application:

Web application (Web app) is a client-server software application, in which the client runs in a web browser. It is stored on a remote server and delivered over the Internet through a browser interface. It is not designed for a specific type of device or an operating system, which means it can be accessed from several devices. Web applications commonly use a combination of server-side script (ASP, PHP, etc) and client-side script (HTML, Javascript, etc.) to be developed.


Hybrid Applications:

Hybrid applications have the characteristic of both web applications and native applications. They combine the elements of both native and Web applications. They are developed using HTML, CSS, and Javascript, and then wrapped into a native application using platforms like Cordova. Since they are designed for various platforms, they don’t require different source codes like native apps, Web application development is obviously faster, simpler and rapid.

5 0
2 years ago
Read 2 more answers
Other questions:
  • Which port, along with a special card and cables, supports the connection of microcomputers, modems, and printers in a local are
    6·1 answer
  • How efficient would a 6-bit code be in asynchronous transmission if it had 1 parity bit, 1 start bit, and 2 stop bits?
    5·1 answer
  • In the game Beehive, you play the role of a worker bee who must watch over her hive. Your duties include (among others) directin
    12·2 answers
  • Which advertising medium has the widest reach on a global front?
    12·1 answer
  • Which of these statements regarding mobile games is true? A. They are typically played indoors. B. They have detailed environmen
    7·1 answer
  • Convert the following binary number to octal (111000)2​
    12·1 answer
  • Which of the following facts determines how often a nonroot bridge or switch sends an 802.1D STP Hello BPDU message?
    14·1 answer
  • Item = "quesadilla"
    7·1 answer
  • You are having a problem with your Windows computer that is isolated to a single graphics editing program that you use every day
    12·1 answer
  • Evie clicks through her presentation slides and realizes they all have transition effects coming from the same location, from th
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!