*95*

# Xylem and Phloem Number in Java

In this section, we will learn **what is xylem and phloem number** and also create Java programs to check if the given number is **xylem** or **phloem**. The **xylem and phloem number program** frequently asked in Java coding tests and academics.

## Xylem and Phloem Number

A number N will be a **xylem number** if the sum of its extreme (first and last) digits is equal to the sum of mean (all digits except first and last) digits. If the sum of extreme digits is not equal to the sum of mean digits, the number is called **phloem number**.

In short, we can say that:

**Xylem Number**

Sum of extreme digits = Sum of mean digits

**Xylem Number**

Sum of extreme digits ≠ Sum of mean digits

### Xylem and Phloem Number Example

Example of Xylem and Phloem Numbers | ||||||
---|---|---|---|---|---|---|

Number | Extreme Digits | Sum of Extreme Digits | Mean Digits | Sum of Mean Digits | Comparing Sum | Xylem or Phloem |

12348 | 1, 8 | 9 | 2, 3, 4 | 9 | 9 = 9 | Xylem |

12225 | 1, 5 | 6 | 2, 2, 2 | 6 | 6 = 6 | Xylem |

825122 | 8, 2 | 10 | 2, 5, 1, 2 | 10 | 10 = 10 | Xylem |

761312 | 7, 2 | 9 | 6, 1, 3, 1 | 11 | 9 ≠ 11 | Phloem |

271389 | 2, 9 | 11 | 7, 1, 3, 8 | 19 | 11 ≠ 19 | Phloem |

17156 | 1, 6 | 7 | 7, 1, 5 | 13 | 7 ≠ 13 | Phloem |

## Steps to find Xylem and Phloem Number

- Read or initialize a number N.
- Find the extreme digits of N.
- Sum up the extreme digits and store the sum in a variable (extreme_sum).
- Find the mean digits of N.
- Sum up the mean and store the sum in a variable (mean_sum).
- Compare both sums (that we get from steps 3 and 5).
- If they are
**equal**, the number is a**xylem** - Else, the number is a
**phloem**

- If they are

Let’s implement the above steps in a Java program and check if the given number is xylem or phloem.

## Xylem and Phloem Number Java Program

**XylemPhloemExample .java**

**Output 1:**

Enter a number: 825122 The sum of extreme digits: 10 The sum of mean digits: 10 825122 is a xylem number.

**Output 2:**

Enter a number: 761312 The sum of extreme digits: 9 The sum of mean digits: 11 761312 is a phloem number.

Next TopicComplex Java Programs