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
In which type of attack does the user respond to several external communication requests? Harry wants to watch a movie online by
Shkiper50 [21]

Answer:

They normaly do that to put a virus on your device And hack into your private info like passwords and credit cards and stuff like that

Explanation:

Always watch a movie leagly

3 0
3 years ago
While many instruments have been "electrified", there is no such thing for the drums.
coldgirl [10]
False, because they are called percussion group
4 0
3 years ago
Read 2 more answers
Waht is the difference between authorization and access control? Access control specifies what a user can do, and authorization
spayn [35]
<h2>Answer:</h2>

Authorization specifies what a user can do, and access control enforces what a user can do.

<h2>Explanation:</h2>

Authorization is simply granting access to an authenticated user of an application. It specifies what a user can and/or cannot do. For example, for a user to access their banking details in an online banking service, they have to be authorized by first authenticating them to prove their identity. Another example is in an organizational system where some users (normally called admins) can access certain database info whereas some other users (normally called the regular users) cannot.

Access control is used to enforce the policies dictated by authorization. In other words, access control enforces the policy of what a user can and/or cannot do. Access control makes authorization possible. It is sometimes called privileges or permissions. For example, the <em>security tab </em>in the operating system of Windows, allow to set access privileges for certain files and/or folders. Another example is in an organizational system where some files on the organization's server are configured in such a way that access to it is restricted and dependent on some further authorization.

5 0
3 years ago
Read 2 more answers
Which tool helps a project manager identify the task that have been completed and the ones that are still outstanding
vodka [1.7K]

Answer:

timeline please make me branliest

4 0
2 years ago
Ellen's laptop has a built-in 802.11n-capable wireless NIC. The wireless NIC worked perfectly yesterday when she loaned it to he
Flura [38]

Answer:

The NIC is disabled in CMOS

Explanation:

CMOS refers to the Complementary Metal Oxide Semiconductor.  It is a technology that is used to generated integrated circuits.

It can be found in various types like microprocessors, batteries, etc

While on the other hand the NIC refers to the network interface controller in which the component of the computer hardware has connected the computer to its network. It can be done via wired and wireless.

Since in the given situation, it is mentioned that Ellen is not able to access the internet through wireless NIC neither it is visible in network connections nor it is shown in device manager so first she assumes that is nic is disabled in CMOS

and the same is to be considered

6 0
3 years ago
Other questions:
  • Your dad just purchased a new desktop with Windows 8 Professional. He is calling you, informing you that he is unable to remote
    9·1 answer
  • Which of the following is a sigh that your computer may have been infected with malicious code
    12·1 answer
  • George and Miguel want to know more about their local and online competitors and about the retail industry. What is the best way
    9·1 answer
  • In order to use an object in a program, its class must be defined.
    9·1 answer
  • When you set up social connections, each generic icon in the contacts list and the People Pane will be replaced with the profile
    12·1 answer
  • what would be the address of the cell, which is intersect of the second row and third column in a worksheet
    8·2 answers
  • Macro photographs are what type of photographs? A. Close-up B. Telephoto C. Abstract D. All of the above
    14·1 answer
  • Picking up sound over a great distance while making it seem to come from close up.
    11·1 answer
  • In order to control access to a company's intranet and other internal networks, all communications pass through a _____ server.
    5·1 answer
  • External hard drives typically connect to a computer via an external port (such as a usb or ____ port) or a wireless connection.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!