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
djyliett [7]
3 years ago
8

Write a method which will take one number as an argument. (Feel free to use static method or instance method) Given a input numb

er (integer) print the digits of the number. You must use while loop and modulus operator. This program must work for any positive integer. Negative integers are not cons idered as inputs.
Computers and Technology
1 answer:
astra-53 [7]3 years ago
7 0

Answer:

// here is code in java.

import java.util.*;

// class definition

class Main

{

// method that return the digits of number

   public static void dig(int num)

   {

   // while loop

       while(num>0)

       {

           // print the digits

           System.out.println(num%10);

           num=num/10;

       }

   }

   //driver method

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

{

   try{

    // scanner object to read input string

       Scanner s=new Scanner(System.in);

        // variable

       int num;

       System.out.print("please enter the number: ");

       //read the number

       num=s.nextInt();

       // validate the input, read a positive number only

       while(num<=0)

       {

           System.out.print("enter a positive number only:");

           num=s.nextInt();

       }

       System.out.println("digit of number are:");

       // call the function

      dig(num);

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read a number from user and assign it to variable "num".Check if it is positive or not.If input is negative then ask user to again enter a positive number till user enter a positive number.Then call the function with input number. In this method it will find the digits of the number in the while loop using modulus "%" operator.

Output:

please enter the number: -345

enter a positive number only:1234

digit of number are:

4

3

2

1

You might be interested in
What problems does the swim coach have? Use details from the story to support your answer.
kobusy [5.1K]
Swimming questions that you need to know how to do
5 0
3 years ago
You are seeking a way to store computer files so you have backup copies anywhere you go.? Which one of the secondary storage typ
garri49 [273]
If you want to know the right answer you should attach an options to choose. Anyway I think the right answer is USB flash-drive. It's possible to create recovery on usb and store any type of files.
3 0
3 years ago
Choose the correct statements about computer-programming languages. Choose all that apply.
Nady [450]

Answer:

Computer-programming languages are like English, French, and German in that they follow set rules and patterns.

Computers understand binary machine language.

Programming languages like BASIC were developed for the convenience of programmers.

Explanation:

8 0
3 years ago
Read 2 more answers
Choose the web design factor from the drop-down menus that best represents each statement. A. Good web pages stick to the point,
Paladinen [302]

Choose the web design factor from the drop-down menus that best represents each statement.

Answer:

A. Good web pages stick to the point, do not have useless information, and showcase important information.

  • Useful content

B. The best websites clearly present a reason for the creation of the site.

  • Purpose

C. The best websites are pleasing to look at and make you want to click further through the pages.

  • Visually appealing

D. It is important for the web designer to understand the needs, interests, and technology level of the target web page visitor.

  • Audience

E. Good websites make it easy to navigate from one page to the other with relevant links in obvious places.

  • Easy to use
4 0
4 years ago
Discuss FOUR challenges that have an impact on domestic tourism
shutvik [7]
Crime rate
unemployment
fluctuations
suspension of terrorism
5 0
4 years ago
Other questions:
  • Pam wants to include a video from a website in an upcoming presentation. However, she knows she will not have access to an inter
    15·2 answers
  • A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-lif
    11·1 answer
  • If a computer file will not open, what should you do? A. Make sure you have the correct software to open it. B. Change the name
    9·1 answer
  • Who can help me on my school we will to google meet and i share my screen
    5·1 answer
  • There are some network modeling tools that can ________ the existing network.
    12·2 answers
  • Which work habits should you follow to increase work efficiency and avoid health issues?
    6·1 answer
  • 6. A genre of video game in which a player chooses a character and builds, upskills and modifies that character is referred to a
    12·2 answers
  • How many times is the second for loop going to loop in this block of code? Write your answer in numeric form in the box provided
    6·1 answer
  • A user may enter some text and the number of times (up to a maximum of 10) to repeat it. Display the text repeated that many tim
    12·1 answer
  • you are working in the headquarters of an organization and you're asked to deal with the interruption in services due to network
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!