DivisibilityTest

DivisibilityTest - //remove the last digit } while (num...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Program: Divisibility test by 3 and 9 / import java.util.*; i public class DivisibilityTest { static Scanner console = new Scanner(System.in); public static void main (String[] args) { int num; int temp; int sum; System.out.print("Enter a positive integer: "); num = console.nextInt(); System.out.println(); temp = num; sum = 0; do { sum = sum + num % 10; //extract the last digit //and add it to sum num = num / 10;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //remove the last digit } while (num > 0); System.out.println("The sum of the digits = " + sum); if (sum % 3 == 0) System.out.println(temp + " is divisible by 3"); else System.out.println(temp + " is not divisible by 3"); if (sum % 9 == 0) System.out.println(temp + " is divisible by 9"); else System.out.println(temp + " is not divisible by 9"); } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Ask a homework question - tutors are online