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]
2 years ago
14

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

Computers and Technology
2 answers:
anyanavicka [17]2 years 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]2 years 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
Identify a data type applied in an input element to create slider controls.
QveST [7]

Answer:

range

Explanation:

8 0
2 years ago
Write a statement to add the key Tesla with value USA to car_makers. Modify the car maker of Fiat to Italy. Sample output for th
marishachu [46]

Answer:

Input code:

car_makers = {'Honda': 'Japan', 'Fiat': 'Germany'}

#add Tesla and USA as corresponding value

car_makers['Tesla'] = 'USA'

#change Fiat entry to Italy instead of Germany

car_makers['Fiat'] = 'Italy'

print(car_makers)

print('Honda made in', car_makers['Honda'])

print('Fiat made in', car_makers['Fiat'])

print('Tesla made in', car_makers['Tesla'])

Explanation:

The first line is a define object in the python code, containing two entries of Honda and Fiat and their respective countries.

The python code adds an entry to the object "car maker" using the bracket notation, the tesla car from USA.

The country of the Fiat car is changed from Germany to Italy, using the bracket notation.

The output of the complete object and the individual cars is given.

<u>output of the python code:</u>

{'Honda': 'Japan', 'Fiat': 'Italy', 'Tesla': 'USA'}

Honda made in Japan

Fiat made in Italy

Tesla made in USA.

7 0
2 years ago
Write a public static method named printArray, that takes two arguments. The first argument is an Array of int and the second ar
Serjik [45]

Answer:

Written in Java

public static void printArray(int myarr[], String s){

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

           System.out.print(myarr[i]+s);

       }

   }

Explanation:

This defines the static method alongside the array and the string variable

public static void printArray(int myarr[], String s){

The following iteration iterates through the elements of the array

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

This line prints each element of the array followed by the string literal

           System.out.print(myarr[i]+s);

       }

   }

The method can be called from main using:

<em>printArray(myarr,s);</em>

Where myarr and s are local variables of the main

5 0
2 years ago
Which feature of a typical professional networking site helps users add professional details to their profile ?
ludmilkaskok [199]
All I  could find are networking cites allow people to take pics of themselves for a personal effect! hope this is what your looking for.
7 0
2 years ago
Read 2 more answers
In one to three sentences describe one reason you would import data into a datebase
Bond [772]

The primary reason that you would import data into a database is because the data already exists somewhere else.

As an example, you may have a spreadsheet that contains names and telephone numbers of a group of people. It is much faster to import this data into a database instead of manually entering the information.

8 0
2 years ago
Other questions:
  • Instructions:Type the correct answer in the box. Spell all words correctly.
    5·2 answers
  • In a spreadsheet, the instructions for carrying out calculations are called __________. recalculations formulas templates macros
    13·1 answer
  • ____ is a program placed on a computer without the user's knowledge that secretly collects information about the user
    14·1 answer
  • Which of the following statements is not true about proper tire care? a.If you see a wear bar across the width of the tread whil
    14·2 answers
  • The major result of treating 1-butyne with 6M aqueous NaOH would be:_______.A. the production of an alkene.B. the production of
    10·1 answer
  • Which of the following sorting algorithms is described by this text? "Take the item at index 1 and see if it is in order compare
    10·1 answer
  • For a class project, Jerome builds a simple circuit with a battery and three light bulbs. On his way to school, Jerome drops his
    9·1 answer
  • A program is divided into 3 blocks that are being compiled on 3 parallel computers. Each block takes an Exponential amount of ti
    6·1 answer
  • Summary: Given integer values for red, green, and blue, subtract the gray from each value. Computers represent color by combinin
    11·1 answer
  • All organizations need good quality cybersecurity to ensure _____. Select 4 options.
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!