K
kim988de
Gast
meine aufgabe lautet.
Input a 5-digit integer n from the keyboard.
Find the sum of the digits. Call it sum.
Verify that either (a) both n and sum are divisible by 3 or (b) both are indivisible by 3.
Your output is:
Given number n = …
Sum of the digits sum = …
Prints one of the following three statements:
(a) Both n and sum are divisible by 3
(b) Both n and sum are indivisible by 3
(c) The famous statement is wrong
Das hier ist mein code
aber irgendwie gibt es mir immer einen error an bei der if condition.
hoffe ihr koennt mir helfen.
thanks.
Input a 5-digit integer n from the keyboard.
Find the sum of the digits. Call it sum.
Verify that either (a) both n and sum are divisible by 3 or (b) both are indivisible by 3.
Your output is:
Given number n = …
Sum of the digits sum = …
Prints one of the following three statements:
(a) Both n and sum are divisible by 3
(b) Both n and sum are indivisible by 3
(c) The famous statement is wrong
Das hier ist mein code
Code:
import java.util.Scanner;
class program
{
public static void main (String args[])
{
Scanner scanner = new Scanner(System.in);
System.out.println("Type the five digit n number");
int n1, n2, n3, n4,n5 ;
n1= scanner.nextInt();
n2= scanner.nextInt();
n3= scanner.nextInt();
n4= scanner.nextInt();
n5= scanner.nextInt();
int n;
n=(n1*10000)+(n2*1000)+(n3*100)+(n4*10)+n5;
System.out.println(+n);
int sum;
sum= +n1+n2+n3+n4+n5;
System.out.printf("The sum is %8d", +sum );
if (n%3 = 0 && sum%3 = 0)
{System.out.println("It is divisible by 3");}
else
{System.out.println("Yes, both are divideable by 3");}
aber irgendwie gibt es mir immer einen error an bei der if condition.
hoffe ihr koennt mir helfen.
thanks.