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
describe briefly one scenario where records stored in a computer frequently need to be searched. state why the searches may be c
Gnoma [55]
Because the string is invalid or your source is not attached to your search engine.
4 0
1 year ago
Read 2 more answers
Which Artificial Intelligence (AI) term is used to describe extracting information from unstructured text using algorithms?
Alla [95]

Answer:

The most basic and useful technique in NLP is extracting the entities in the text. It highlights the fundamental concepts and references in the text. Named entity recognition (NER) identifies entities such as people, locations, organizations, dates, etc. from the text.

5 0
2 years ago
Locker doors There are n lockers in a hallway, numbered sequentially from 1 to n. Initially, all the locker doors are closed. Yo
kow [346]

Answer:

// here is code in C++

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables

   int n,no_open=0;

   cout<<"enter the number of lockers:";

   // read the number of lockers

   cin>>n;

   // initialize all lockers with 0, 0 for locked and 1 for open

   int lock[n]={};

   // toggle the locks

   // in each pass toggle every ith lock

   // if open close it and vice versa

   for(int i=1;i<=n;i++)

   {

       for(int a=0;a<n;a++)

       {

           if((a+1)%i==0)

           {

               if(lock[a]==0)

               lock[a]=1;

               else if(lock[a]==1)

               lock[a]=0;

           }

       }

   }

   cout<<"After last pass status of all locks:"<<endl;

   // print the status of all locks

   for(int x=0;x<n;x++)

   {

       if(lock[x]==0)

       {

           cout<<"lock "<<x+1<<" is close."<<endl;

       }

       else if(lock[x]==1)

       {

           cout<<"lock "<<x+1<<" is open."<<endl;

           // count the open locks

           no_open++;

       }

   }

   // print the open locks

   cout<<"total open locks are :"<<no_open<<endl;

return 0;

}

Explanation:

First read the number of lockers from user.Create an array of size n, and make all the locks closed.Then run a for loop to toggle locks.In pass i, toggle every ith lock.If lock is open then close it and vice versa.After the last pass print the status of each lock and print count of open locks.

Output:

enter the number of lockers:9

After last pass status of all locks:

lock 1 is open.

lock 2 is close.

lock 3 is close.

lock 4 is open.

lock 5 is close.

lock 6 is close.

lock 7 is close.

lock 8 is close.

lock 9 is open.

total open locks are :3

5 0
2 years ago
Excerpt from "How Prepared Are Students for College Level Reading? Applying a Lexile-Based Approach."
Lesechka [4]
The options that gives that answer to the question how it was determined that students are graduating from high school unprepared for college-level work is A. high rates of enrollment in remedial college courses.
The other options present the facts how graduates are successful, but we can see by the number of people who take these remedial courses that that is actually not the case.
7 0
1 year ago
Read 2 more answers
Write a script to check command arguments (3 arguments maximum). Display the argument one by one. If there is no argument provid
serious [3.7K]

Answer:-args (

if:args=true

-cont

if:args=false

-cont investigating

if:args=irrelevance

-loop restate args

)

compile exec

Explanation:

7 0
1 year ago
Other questions:
  • U.S. industries like steel, computers, and energy need to be protected from foreign competition to ensure which of the following
    6·2 answers
  • Samantha was calculating a mathematical formula on an electronic spreadsheet. She used multiple values to recalculate the formul
    12·2 answers
  • Which statement regarding dialogues in multiplayer games is true? Dialogues are based only on players’ actions.
    7·2 answers
  • In 2–3 sentences, describe how you would change the background of a group of cell
    6·2 answers
  • In cell B16, enter a function to calculate the total attendance for the years 2014 through 2018 using the totals in the range B1
    10·1 answer
  • A good way to avoid skids is to _____ when coming into a turn. A. accelerate B. decelerate C. counter steer D. cover brake
    8·2 answers
  • Design a program that asks the user for a series of names (in no particular order). After the final person’s name has been enter
    5·1 answer
  • Which of the following should get a Page Quality (PQ) rating of Low or Lowest? Select all that apply. True False A page with a m
    8·1 answer
  • g 18.6 [Contest 6 - 07/10] Reverse an array Reversing an array is a common task. One approach copies to a second array in revers
    8·1 answer
  • A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first s
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!