The code from 3.5.8: Divisibility: I wrote following:



import java.util.Scanner;



public class Divisibility

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

int dividend = input.nextInt();

int divisor = input.nextInt();

System.out.println("Enter the dividend: " + dividend);

System.out.println("Enter the divisor: " + divisor);



if (divisor == 0)



{



System.out.println(dividend + " is not divisible by " + divisor + "!");



}



else if (dividend%divisor == 0)



{



System.out.println(dividend + " is divisible by " + divisor + "!");



}

}

}



But it gives extra 0 and 10. It supposed to give Expected result.



Expected result:Enter the dividend: Enter the divisor: 10 is not divisible by 0!


Your result:
Enter the dividend: 10Enter the divisor: 010 is not divisible by 0!

Difference:
Enter the dividend: 10Enter the divisor: 010 is not divisible by 0!

Expected result:
Enter the dividend: Enter the divisor: 9001 is not divisible by 0!

Your result:
Enter the dividend: 9001Enter the divisor: 09001 is not divisible by 0!

Difference:
Enter the dividend: 9001Enter the divisor: 09001 is not divisible by 0!

Expected result:
Enter the dividend: Enter the divisor: 8 is divisible by 2!

Your result:
Enter the dividend: 8Enter the divisor: 28 is divisible by 2!

Difference:
Enter the dividend: 8Enter the divisor: 28 is divisible by 2!