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
svetoff [14.1K]
2 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]2 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
How is the IT function organized in your school or place of employment? Create an organization chart showing how the IT organiza
kkurt [141]

Answer:

A

At my place of employment (which is a knowledge based business) the IT function integrates with all aspect of the operations which include:

  1. top management,
  2. business units,
  3. customers,
  4. non-IT suppliers, and
  5. IT providers.

The IT function manages the entire information technology value chain within the organisation. It provides solutions with regard to the software and hardware IT infrastructure.

We have a locally developed software which forms the frame work upon which our business rests. We refer to this as the Primary Production software. Other software which come preinstalled or post-installed on our machines are referred to as Secondary Production softwares.

All the hardware upon which the Primary and Secondary Production software run on are also managed the the IT Unit.

Every aspect of our operations described above must at somepoint interface or require the expertise of the IT Unit.

Our customers rely on the Primary software.

Business Units must a manager key functions for the Primary software on the backend and rely on secondary production software for other administrative tasks.

B

Please see attached the organisational chart that shows how the above relationships interplay.

C

At our organization, it is critical for the IT function to be centralized.

All decisions are made from the IT unit of the head quarters and cascaded into business units and other IT units at various branch locations.

6 0
2 years ago
A small company is moving towards sharing printers to reduce the number of printers used within the company. The technician has
Misha Larkins [42]

Answer:

Security risk associated with sharing a printer are

  1. Printer Attacks
  2. Theft
  3. Breach of data
  4. Vulnerable Network

Explanation:

Printer Attacks

A network printer can be used for a DDoS attack.As printer are not very secured and are a weak link in network these can be easily exploited by the hackers for any kind of malicious activities and even lanching a DDoS attack.

DDoS attack is denial of service attack in which network is flooded with malicious traffic which cause it to choke and make it inaccessible for users.

Theft

Physical theft of document can be an issue.Anyone can just took printed pages from printer tray by any one.

Breach of Data

The documents which are printed are usually stored in printer cache for some time which can be accessed by any one connected to the network. Any document containing confidential information which are printed on network printer can fall in wrong hands.

Vulnerable Network

As mentioned a single unsecured network printer can pose great threat to entire network as it can provide a way into the network.

8 0
2 years ago
Which is the correct notation to specify the following inheritance?
Alika [10]

Answer:

Create the student class object which inherit the printinfo() from the abstract class People

Explanation:

Classes in object-oriented programming are blueprints of a defined type of data structure.

An object of an abstract class cannot be instantiated. So, the People class in question, is only inherited by the Student class which able to use the define printinfo() method.

4 0
1 year ago
. Write a function wordscramble that will receive a word in a string as an input argument. It will then randomly scramble the le
inysia [295]

Answer: You can use the function randperm() to generate a random permutation of the indexes. so then you would use the random permutation to reorder the string array

Explanation:

4 0
2 years ago
Which are technical and visual demands that need to be considered when planning a project? Choose three answers
iren [92.7K]

Answer: Resolution or DPI, deliverables, and file types are important technical and visual demands to consider when planning a project.

Explanation: Keep in mind whether or not the project will be published in print or on the Web.

4 0
2 years ago
Other questions:
  • PLEASE HELP!! WILL GIVE BRAINLIEST!!
    15·2 answers
  • ________ is used to undo unwanted database changes.
    15·2 answers
  • Use a VLOOKUP function in cell I5 to identify and calculate the federal withholding tax. Use the tax rates from the range D21:E2
    15·1 answer
  • The following checksum formula is widely used by banks and credit card companies to validate legal account numbers: d0 + f(d1) +
    13·1 answer
  • What is the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz? Group of answer choices
    6·1 answer
  • As a digital forensics examiner, it’s a good idea to build a list of references for information on privacy laws in other countri
    13·1 answer
  • Universal Containers (UC) uses a custom object called Vendor. The Vendor custom object has a Master-Detail relationship with the
    10·1 answer
  • Write an expression to print each price in stock prices.
    15·1 answer
  • In this exercise you will debug the code which has been provided in the starter file. The code is intended to take two strings,
    7·1 answer
  • A group of developers for a startup company store their source code and binary files on a shared open-source repository platform
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!