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
densk [106]
4 years ago
11

write a JAVA program that has the following methods. a. int firstDigit(int n) , returning the first digit of the argument b. int

lastDigit(int n) , returning the last digit of the argument c. int digits(int n) , returning the number of digits of the argument For example, firstDigit(1729) is 1, last digit(1729) is 9, and digits(1729) is 4. d. a main method that
Computers and Technology
1 answer:
ladessa [460]4 years ago
7 0

Answer:

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        System.out.println(firstDigit(1729));
  4.        System.out.println(lastDigit(1729));
  5.        System.out.println(digits(1729));
  6.    }
  7.    public static int firstDigit(int n){
  8.        String n_str = Integer.toString(n);
  9.        char firstChar = n_str.charAt(0);
  10.        String firstDigit = Character.toString(firstChar);
  11.        return Integer.parseInt(firstDigit);
  12.    }
  13.    public static int lastDigit(int n){
  14.        String n_str = Integer.toString(n);
  15.        char lastChar = n_str.charAt(n_str.length() - 1);
  16.        String lastDigit = Character.toString(lastChar);
  17.        return Integer.parseInt(lastDigit);
  18.    }
  19.    public static int digits(int n){
  20.        String n_str = Integer.toString(n);
  21.        return n_str.length();
  22.    }
  23. }

Explanation:

Firstly we create a method firstDigit that will return the first digit of the input number (Line 8 - 13). This method will convert the input number, n, to string using Integer toString method (Line 9) and assign it to n_stry variable. Next, use charAt method with 0 index to get the first character from n_str and assign it to firstChar variable (Line 10). Next, use Character toString method to convert the firstChar to string type (Line 11) because the parseInt method which is used in Line 12 will only work on String type but not char type. The function return the firstDigit with integer type (Line 12). The parseInt method has converted the string type firstDigit to integer.

The logical steps defined for lastDigit method are similar to firstDigit except that we need to use .length() method to get the length of the digit string and calculate the last index to get the last digit (Line 17).

The digits method (Line 22 -25) will convert the input number to string and then use .length() method to return the length of the number string which is equivalent of number of digit as output.  

You might be interested in
In black and white,<br><br> we must be more conscious of image
scZoUnD [109]

is it true or false is so it is false

3 0
3 years ago
The tools, skills, knowledge, and machines created and used by humans is known as.
miskamm [114]

Answer:

Human capital

Explanation:

It means the economic value of workers experience and skills

7 0
2 years ago
What is the difference between coding with html and coding with python
dsp73

Answer:

Python is an object-oriented programming language that is designed to be accessible and simple for all users, HTML is a web language and is used globally to define the structure of web pages by using various tags. HTML is not a programming language it's a markup language which is used to formatting web pages. Python is a general purpose scripting language which can be used to develop a wide range of programs.

5 0
3 years ago
X = 1 if (A = 1 OR B = 1) OR (A = 0 AND B = 1
Gnoma [55]

Answer:

For question a, it simplifies.  If you re-express it in boolean algebra, you get:

(a + b) + (!a + b)

= a + !a + b

= b

So you can simplify that circuit to just:

x = 1 if b = 1

(edit: or rather, x = b)

For question b, let's try it:

(!a!b)(!b + c)

= !a!b + !a!bc

= !a!b(1 + c)

= !a!b

So that one can be simplified to

a = 0 and b = 0

I have no good means of drawing them here, but hopefully the simplification helped!

4 0
3 years ago
When was Microsoft released to public schools?
Studentka2010 [4]
April 4
1975...$.$.$.........&.$.$.$....................
8 0
4 years ago
Other questions:
  • One group of students did an experiment to study the movement of ocean water. The steps of the experiment are listed below.
    10·1 answer
  • . Constructors can / cannot (circle correct choice) be called explicitly as if they were regular member functions.
    10·1 answer
  • A(n) ________ CPU has two processing paths, allowing it to process more than one instruction at a time.
    9·2 answers
  • The electric company gives a discount on electricity based upon usage. The normal rate is $.60 per Kilowatt Hour (KWH). If the n
    7·1 answer
  • How does the use of the computer impact businesses
    13·1 answer
  • Interruption attacks are also called ___ attacks:
    8·1 answer
  • Which network component blocks status?
    9·1 answer
  • What is the definition of Overflow Error?
    5·1 answer
  • What is motivation and state the two forms​
    14·1 answer
  • A(n) __________ structure is a structure that causes a statement or a set of statements to execute repeatedly.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!