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
svetoff [14.1K]
3 years ago
15

Writing in Java, write a program that prompts the user to input an integer and then outputs both the individual digits of the nu

mber and the sum of the digits. For example, the program should: ouput the individual digits of 3456 as 3 4 5 6 and the sum as 18, output the individual digits of 8030 as 8 0 3 0 and the sum as 11, output the individual digits of 2345526 as 2 3 4 5 5 2 6 and the sum as 27, output the individual digits of 4000 as 4 0 0 0 and the sum as 4, and output the individual digits of -2345 as 2 3 4 5 and the sum as 14.
Computers and Technology
1 answer:
larisa [96]3 years ago
6 0

Answer:

//Here is code in java.

import java.util.*;

class Main

{

public static void main (String[] args) throws java.lang.Exception

{

   try{

       int in;

     //scanner class object to read the input

    Scanner scr=new Scanner(System.in);

     // variable to keep running total

    int total=0;

    System.out.println("please enter an Integer:");

     // read the input first time

    in=scr.nextInt();

    System.out.print("individual digits of "+in+" is ");

    if(in<0)

    {

        in=-(in);

    }

   

 

     //call the function to print the digits of number

   print_dig(in);

   System.out.println();

    //calculate the sum of all digits

   do{

       int r=in%10;

       total=total+r;

       in=in/10;

   }while(in>0);

    //print the sum

   System.out.println("total of digits is: "+total);

     

   }catch(Exception ex){

       return;}

}

 //recursive function to print the digits of number

public static void print_dig(int num)

{  

    if(num==0)

    return;

    else

    {

    print_dig(num/10);

    System.out.print(num%10+" ");

    }

}

}

Explanation:

Read a number with the help of object of scanner class.if the input is negative

then make it positive number before calling the function print_dig().call

the recursive method print_dig() with parameter "num".It will extract the digits

of the number and print then in the order. Then in the main method, calculate

sum of all the digits of number.

Output:

please enter an Integer:                                                                                                  

3456                                                                                                                      

individual digits of 3456 is 3 4 5 6                                                                                      

total of digits is: 18

please enter an Integer:                                                                                                  

-2345                                                                                                                      

individual digits of -2345 is 2 3 4 5                                                                                      

total of digits is: 14

You might be interested in
When is the redo log buffer written to the redo log file?
natka813 [3]

Answer: B)The redo log buffer becomes one-third full.

Explanation:Redo log buffer is the type of buffer file that is present for storing the changes that have been done in data. Database changes are the made goes in the records of the redo entries.the change of the buffer to the redo files is done when the buffer contains change records which are full till the one-third section, thus conversion takes place from the redo buffer to the redo files.

5 0
2 years ago
11.
Svetllana [295]
11. is battle of the bulge
12. rationing
13. trade embargo act
14. germany won the battle is not true
15. force jews to wear stars sown to their clothing to be caught without was punishable by death
3 0
3 years ago
If you use your computer primarily for telnet into a remote computer, will you have a large long distance telephone bill?
Nikolay [14]

If you use your computer primarily for telnet into a remote computer, a person will not have a large long distance telephone bill.

<h3>What is telnet used for?</h3>

Telnet is known to be a kind of a network protocol that is said to be used to virtually look into a computer and to give a two-way, working hand in hand and text-based communication channel that exist between two machines.

Note that, If you use your computer primarily for telnet into a remote computer, a person will not have a large long distance telephone bill because it does not apply in any way.

Learn more about telnet from

brainly.com/question/23640188

#SPJ1

4 0
2 years ago
As our use of the internet increases e-safety becomes essential.<br> Discuss why e-safety is needed.
nlexa [21]

Answer:

The answer is described below

Explanation:

E safety means means protection of private information and personal safety when using the internet. E safety involve the protection of private information, passwords against identity theft or property theft. A persons  private information, passwords can be gotten through the use of phishing or malwares.

Also, the use of internet has exposed people to cyber bullying(i.e abuse of an individual), stalking, engaging underage children into sexual relationships and sextortion.

E safety  help protect children from harmful content and services as those listed.

8 0
3 years ago
Which of these is not used by analysts when adopting CASE tools? (1 point) (Points : 1.5) communicating more effectively with us
mojhsa [17]

Answer: expediting the local area network

Explanation: Case tools are the tools or service that helps in the software development but the automatic activity. This tool can be applied on various applications like mobile apps, E-commerce websites etc.

Analyst focus on the features like improving productivity ,low time consumption,integration of the work and making the communication better with the users ,helps in producing large amount of the documents etc.

The only factor not accepted by analyst is accomplishing the operation in the LAN(local area network) as it does not facilitates this operation because it is not software development process.

4 0
3 years ago
Other questions:
  • Lossless and lossy are the two (2) universally known categories of compression algorithms. Compare the two (2) categories of alg
    8·2 answers
  • What is the main storage location of a computer
    13·1 answer
  • Before creating a brief to design a product, what is needed
    8·1 answer
  • 50 POINTS! What can be viewed in the Tasks folder? Check all that apply.
    13·2 answers
  • Unlike radio frequency identification (RFID) tags, bar codes: Question 30 options: require a reader that tunes into a specific f
    14·1 answer
  • Who has a brainpop acct. can i pls use it !
    12·1 answer
  • Complete the sentence with the correct response.
    9·1 answer
  • 6.23 Lab training: Unit tests to evaluate your program Auto-graded programming assignments may use a Unit test to test small par
    13·1 answer
  • What instructions would a computer have the hardest time completing correctly
    12·1 answer
  • Write a program using LinkedList class and ListIterator interface to demonstrate the following activities:
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!