Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
// Exercise5_2.java: Create a method for summarizing digits in an int public class Exercise5_2 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter a number: "); int value = input.nextInt(); System.out.println("The sum of digits for " + value + " is " + sumDigits(value)); } public static int sumDigits(long n) { int temp = (int)Math.abs(n); int sum = 0; while (temp != 0) { int remainder = temp % 10; sum += remainder; temp = temp / 10; } return sum; } } public class Exercise5_4 { public static void main(String[] args) { System.out.println(reverse(12345)); } public static int reverse(int number) { int result = 0; while (number != 0) { int remainder = number % 10; result = result * 10 + remainder; number = number / 10; } return result; } } public class Exercise5_6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter line number: "); int lineNumber = input.nextInt(); displayPattern(lineNumber); } public static void displayPattern(int n) { for (int row = 1; row <= n; row++) { // Print spaces for (int i = row; i < n; i++) System.out.print(" "); // Print numbers for (int i = row; i >= 1; i--) System.out.print(" " + i); System.out.println(); } } }