Advertisement
Guest User

Untitled

a guest
May 13th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import java.util.*;
  2. public class work13
  3. {
  4. static Scanner reader=new Scanner (System.in);
  5. public static boolean sederYored (int num)
  6. {
  7. int x=0;
  8. while(num>0)
  9. {
  10. if(num%10<x)
  11. return false;
  12. x=num%10;
  13. num/=10;
  14. }
  15. return true;
  16. }
  17. public static boolean sederOle (int num)
  18. {
  19. int x=0;
  20. while (num>9)
  21. {
  22. x=num%10;
  23. num/=10;
  24. if(num%10>x)
  25. return false;
  26. }
  27. return true;
  28. }
  29. public static void main(String args[])
  30. {
  31. System.out.println("Enter a natural number");
  32. int number = reader.nextInt();
  33. int zero = 0;
  34. int a;
  35. int b;
  36. int total = 0;
  37. int count = 1;
  38. if(sederOle(number))
  39. {
  40. while(number>0)
  41. {
  42. a = number%10;
  43. b = a%10;
  44. total = a+b;
  45. count++;
  46. }
  47. double avg = total/count;
  48. System.out.println("the avg of the numbers is " + avg);
  49. }
  50. else
  51. {
  52. if(sederYored(number))
  53. {
  54. while(number>0)
  55. {
  56. a = number%10;
  57. b = a%10;
  58. total = a+b;
  59. count++;
  60. }
  61. double avg = total/count;
  62. System.out.println("the avg of the numbers is " + avg);
  63.  
  64. }
  65. else
  66. {
  67. while(number>0)
  68. {
  69. a = number%10;
  70. b = a%10;
  71. total = a+b;
  72. }
  73. System.out.println("the sum of the numbers is " + total);
  74.  
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement