Results 1 to 2 of 2
  1. #1
    kadanakanz is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Checking Multiples from arguments?

    I have just started learning Java and I recently got a homework question which I'm unsure of how to do.
    Firstly, I have to grab a number from the argument.
    Then I check if its a multiple of 5 (0 is counted as a multiple of 5).
    IF a multiple of 5, I type "it is a multiple of 5"
    IF not, I type "it is not a multiple of "5".

    Java Code:
    public class Exercise1 {
    	public static void main(String[] args) {
    		int numToCheck = Integer.parseInt(args[0]);
    
    		for (int multiple = 0; multiple = Math.pow(numToCheck, 5); multiple++) {
    			System.out.println(numToCheck + " is a multiple of 5");
    			return;
    		}
    
    		System.out.println(numToCheck + " is not a multiple of 5");
    	}
    }
    So far I have this. When I try to run it in Eclipse, I get the error "Type mismatch: cannot convert from double to boolean."

    Can anyone help me?
    Last edited by kadanakanz; 05-16-2013 at 09:05 AM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default Re: Checking Multiples from arguments?

    Have a look at the % operator (modulo operator); if a number n is a multiple of 5, then n%5 == 0.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. replaceAll() multiples- looking for elegant solution
    By Redefine12 in forum New To Java
    Replies: 5
    Last Post: 07-21-2012, 09:14 AM
  2. Print Odd Multiples of 3
    By mp3_1 in forum New To Java
    Replies: 9
    Last Post: 11-22-2011, 10:09 PM
  3. Replies: 8
    Last Post: 09-23-2010, 01:07 AM
  4. Multiples Integers from a String
    By AndrewM16921 in forum New To Java
    Replies: 3
    Last Post: 04-01-2009, 01:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •