Your output is:

Given number =

Sum of digits=

One of the following

a. Both number and sum are divisible by 3

b. Both number and sum are indivisible by 3

c. The famous statement is wrong

This is what I have so far..

Expand|Select|Wrap|Line Numbers

- import java.util.*;
- class Divisibility
- {
- public static void main(String args[])
- {
- int number;
- boolean done = false;
- Scanner input = new Scanner(System.in);
- System.out.println("Please input a 5-digit number");
- int number = input.nextInt();
- {
- String numberStr = Integer.toString(number); //to get the number of digits in "number"
- int sum = 0;
- for(int i = 0; i < numberStr.length(); i++)
- {
- int remainder = number % 10;
- sum += remainder;
- number /= 10;
- System.out.println("Sum of the digits: "+sum);
- }
- if(number%3==0 && !done)
- {
- else
- {
- if(!done)System.out.println("Both n and sum are indivisible by 3")
- else
- if(!done)System.out.println("The famous statment is wrong 3")
- System.out.println("Both n and sum are divisible by 3")done = true;
- }
- System.out.println("Both n and sum are divisible by 3")done = true;
- }
- }
- }}