Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class work13
- {
- static Scanner reader=new Scanner (System.in);
- public static boolean sederYored (int num)
- {
- int x=0;
- while(num>0)
- {
- if(num%10<x)
- return false;
- x=num%10;
- num/=10;
- }
- return true;
- }
- public static boolean sederOle (int num)
- {
- int x=0;
- while (num>9)
- {
- x=num%10;
- num/=10;
- if(num%10>x)
- return false;
- }
- return true;
- }
- public static void main(String args[])
- {
- System.out.println("Enter a natural number");
- int number = reader.nextInt();
- int zero = 0;
- int a;
- int b;
- int total = 0;
- int count = 1;
- if(sederOle(number))
- {
- while(number>0)
- {
- a = number%10;
- b = a%10;
- total = a+b;
- count++;
- }
- double avg = total/count;
- System.out.println("the avg of the numbers is " + avg);
- }
- else
- {
- if(sederYored(number))
- {
- while(number>0)
- {
- a = number%10;
- b = a%10;
- total = a+b;
- count++;
- }
- double avg = total/count;
- System.out.println("the avg of the numbers is " + avg);
- }
- else
- {
- while(number>0)
- {
- a = number%10;
- b = a%10;
- total = a+b;
- }
- System.out.println("the sum of the numbers is " + total);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement