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
Otrada [13]
3 years ago
13

Design a function int maxDigit (int num) to find and return the greatest digit from the arguments value num.

Computers and Technology
1 answer:
AfilCa [17]3 years ago
3 0

Answer:

Below is the required JAVA Code:

Explanation:

public static int largestDigit(int n) {

   if (n < 0) {

       return largestDigit(-1 * n);

   } else if (n == 0) {

       return 0;

   } else {

       int digit = n % 10;

       int maxDigit = largestDigit(n / 10);

       if (digit > maxDigit)

           maxDigit = digit;

       return maxDigit;

   }

}

\color{red}Method\;tested\;in\;a\;complete\;java\;program\;if\;you\;are\;interested.

public class LargestDigitRecursive {

   public static int largestDigit(int n) {

       if (n < 0) {

           return largestDigit(-1 * n);

       } else if (n == 0) {

           return 0;

       } else {

           int digit = n % 10;

           int maxDigit = largestDigit(n / 10);

           if (digit > maxDigit)

               maxDigit = digit;

           return maxDigit;

       }

   }

   public static void main(String[] args) {

       System.out.println(largestDigit(14263203));

       System.out.println(largestDigit(845));

       System.out.println(largestDigit(52649));

       System.out.println(largestDigit(3));

       System.out.println(largestDigit(0));

       System.out.println(largestDigit(-573026));

       System.out.println(largestDigit(-2));

   }

}

OUTPUT:

6

8

9

3

0

7

2

You might be interested in
Hello my name is fvgrbhcdnxjm
san4es73 [151]
I’m guessing free points?
3 0
3 years ago
_______________ are distinguished from microcontrollers by their complexity and increased on-chip resources.A. Systems on a chip
weeeeeb [17]

Answer:

the correct option is (A)

Explanation:

According to the given scenario, the system on a chip is a chip that is different from the microcontrollers in terms of complexity and rise on the chip resources

The system on a chip is a circuit i.e. integrated most the computer things

hence, the correct option is (A).

Therefore the rest of the options are wrong

6 0
3 years ago
Read 2 more answers
2560x1600 (apple)vs 1920x1200 (Dell), is there a big difference between those 2 based on screen resolution ? ​
Solnce55 [7]

Answer:

Yes

Explanation:

1920x1200 is a non-standard resolution which may not be fully supported, usually 1920x1080 (1080p) is preferred and has been standardised as a display resolution.

2560x1600 (WQXGA) is a more standardised display resolution, and will offer a lot sharper and crisper images as more pixels are being used to render the image. As a rule of thumb, the higher resolution - the better.

The difference between these two resolutions is about the same difference as 1080p and 2k, you are going to get twice as crisp an image.

However there are other factors, such as refresh rate that may come into play with a comparison with these two.

3 0
4 years ago
How can I convert a string to a int? in Java
Deffense [45]

Answer:

int

Explanation:

5 0
3 years ago
Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes rece
amm1812

Answer:

a= input("Enter the last name of first candidate: ")

aVotes= int(input("Enter Number of votes cast for "+ a + ": "))

b= input("Enter the last name of second candidate: ")

bVotes= int(input("Enter Number of votes cast for "+ b + ": "))

c= input("Enter the last name of third candidate: ")

cVotes= int(input("Enter Number of votes cast for "+ c + ": "))

d= input("Enter the last name of fourth candidate: ")

dVotes = int(input("Enter Number of votes cast for "+ d + ": "))

e= input("Enter the last name of fifth candidate: ")

eVotes = int(input("Enter Number of votes cast for "+ e + ": "))

votes= [aVotes,bVotes,cVotes,dVotes,eVotes]

aPercent= (round((aVotes/sum(votes))*100, 2))

bPercent= (round((bVotes/sum(votes))*100, 2))

cPercent= (round((cVotes/sum(votes))*100, 2))

dPercent= (round((dVotes/sum(votes))*100, 2))

ePercent= (round((eVotes/sum(votes))*100, 2))

print( a, ":", aVotes,"Votes", aPercent,"%")

print( b, ":", bVotes,"Votes", bPercent,"%")

print( c, ":", cVotes,"Votes", cPercent,"%")

print( d, ":", dVotes,"Votes", dPercent,"%")

print( e, ":", eVotes,"Votes", ePercent,"%")

winner= max(votes)

if winner==aVotes:

   print(a," is the Winner")

elif winner==bVotes:

   print(b," is the Winner")

elif winner==cVotes:

   print(c," is the Winner")

elif winner==dVotes:

   print(d," is the Winner")

elif winner==eVotes:

   print(e," is the Winner")

else:

   None

Explanation:

  • First section

<em> a= input("Enter the last name of first candidate: ") </em>

<em>aVotes= int(input("Enter Number of votes cast for "+ a + ": ")) </em>

<em>b= input("Enter the last name of second candidate: ") </em>

<em>bVotes= int(input("Enter Number of votes cast for "+ b + ": ")) </em>

<em>c= input("Enter the last name of third candidate: ") </em>

<em>cVotes= int(input("Enter Number of votes cast for "+ c + ": ")) </em>

<em>d= input("Enter the last name of fourth candidate: ") </em>

<em>dVotes = int(input("Enter Number of votes cast for "+ d + ": ")) </em>

<em>e= input("Enter the last name of fifth candidate: ") </em>

<em>eVotes = int(input("Enter Number of votes cast for "+ e + ": ")) </em>

Collects the last name and the number of  votes cast

  • Second section

<em>votes= [aVotes,bVotes,cVotes,dVotes,eVotes] </em>

<em />

places all the votes in a list.

The reason for this is to allow us use the "sum function" and "max function", to get the sum of all the votes.

  • Third section

<em>aPercent= (round((aVotes/sum(votes))*100, 2)) </em>

<em>bPercent= (round((bVotes/sum(votes))*100, 2)) </em>

<em>cPercent= (round((cVotes/sum(votes))*100, 2)) </em>

<em>dPercent= (round((dVotes/sum(votes))*100, 2)) </em>

<em>ePercent= (round((eVotes/sum(votes))*100, 2)) </em>

calculates the percentage of all the votes cast for the individual candidates

  • Fourth section

<em>print( a, ":", aVotes,"Votes", aPercent,"%") </em>

<em>print( b, ":", bVotes,"Votes", bPercent,"%") </em>

<em>print( c, ":", cVotes,"Votes", cPercent,"%") </em>

<em>print( d, ":", dVotes,"Votes", dPercent,"%") </em>

<em>print( e, ":", eVotes,"Votes", ePercent,"%") </em>

prints out the candidates name, number of votes received and the percentage

  • Fifth section

winner= max(votes)

gets the maximum votes cast

  • Sixth Section

if winner==aVotes:

   print(a," is the Winner")

elif winner==bVotes:

   print(b," is the Winner")

elif winner==cVotes:

   print(c," is the Winner")

elif winner==dVotes:

   print(d," is the Winner")

elif winner==eVotes:

   print(e," is the Winner")

else:

   None

uses if statements to compare the maximum votes with the votes gotten by all the candidates to get a winner

4 0
3 years ago
Other questions:
  • Will give brainliest and good amount of points, no false answers.
    5·1 answer
  • Which is the best description of a hierarchical report?
    13·1 answer
  • Why are video games interesting?
    5·1 answer
  • What could break the circuit between your home and an electric power plant?
    15·2 answers
  • Analog signals consists of individual electric pulses that represents bits group together into bytes {True/False}
    13·1 answer
  • Of the measures of feasibility in the accompanying figure, ____ considers points such as "Does the proposed platform have suffic
    14·1 answer
  • Why are problem-solving strategies important? Choose all that apply. ensures important factors are taken into consideration ensu
    12·1 answer
  • Which of the following is the most appropriate unit to describe the rate at which data is transferred using the internet?
    6·2 answers
  • A user is connected to his personal mobile hotspot device at a library for internet access. He notices the display shows two con
    10·1 answer
  • What are possible consequences for cyberbullying?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!