i have to code a program that ask for the user to enter a positive integer and then I have to find if the value that was enter is divisible by 11 (with no remainder) and display "yes" if it is divisible and "no" if it is not. <<My program so far does this <<<
if the user enter's a non postive integer the program should continue asking for a positive value until the user does so. <<<but im having difficulty to do this,please help<<<<<<
My code so far:
public static void main(String[] args) {
// TODO Auto-generated method stub
int num, temp, sum;
char sign;
System.out.println("Enter a positive integer: ");
num = console.nextInt();
System.out.println();
temp = num;
sum = 0;
sign = '+';
do
{
switch (sign)
{
case '+' :
sum = sum + num % 10;
sign = '-';
break;
case '-' :
sum = sum - num % 10;
sign = '+';
}
num = num / 10;
}
while (num > 0);
if (sum % 11 == 0)
System.out.println(" Yes, it is divisible by 11");
else
System.out.println("No, it is not divisible by 11");
}
}
thnk you guys