The program below is the answer to Deitel’s Java How to Program (9th Edition) Chapter 2 Exercise 2.26.
Question: Write an application that reads two integers, determines whether the first is a multiple of the second and prints the result. [Hint: Use the remainder operator.]
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.26 - Multiples<br /> * This Program Determines Whether The First Number Is A Multiple Of The Second Number<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class Ex02_26 {<br /> public static void main (String [] args) {<br /><br /> Scanner numbers = new Scanner (System.in); <br /><br /> int num1;<br /> int num2; <br /> int check;<br /> <br /> System.out.print ("Enter First Number: ");<br /> num1 = numbers.nextInt();<br /> System.out.print ("Enter Second Number: ");<br /> num2 = numbers.nextInt();<br /> check = num2%num1;<br /> <br /> System.out.println ();<br /> <br /> if (check == 0)<br /> System.out.printf ("The Number %d is a multiple of %d", num1, num2);<br /> else<br /> System.out.printf ("The Number %d is not a multiple of %d", num1, num2);<br /><br /> }<br />}<br /> |
1 Comment
Thanks Dear