-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXylemPhloemExample.java
More file actions
39 lines (39 loc) · 1.3 KB
/
Copy pathXylemPhloemExample.java
File metadata and controls
39 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class XylemPhloemExample {
public static void main (String [] args) {
//the variables extreme_sum stores the sum of extreme digits
//the variable mean_sum stores the sum of mean digits
int num , extreme_sum = 0 , mean_sum = 0 , n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
//reading an integer from the user
num = sc.nextInt();
//finds the absolute value of the given number
num = Math.abs(num);
//copying the given number into n
n=num;
//the while loop executes until the specific condition becomes false
while(n!=0) {
//return true if one of the condition is true
if(n==num || n<10 )
//finds the last digit and add it to the variable extreme_sum
extreme_sum = extreme_sum + n% 10;
else
//finds the mean digits and add it to variable mean_sum
mean_sum = mean_sum + n%10;
//removes the last digit from the number
n = n/10;
}
System.out.println("The sum of extreme digits:"+ extreme_sum);
System.out.println("The sum of mean digits:"+ mean_sum);
//comparing the sum of extreme digits and with the sum of mean digits
if(extreme_sum == mean_sum)
//prints sums are equal
System.out.println(num+" is a xylem number.");
else
//prints if sums are not equal
System.out.println(num+" is a phloem number");
}
}