The Artima Developer Community
Sponsored Link

Java Answers Forum
determining mulitples

3 replies on 1 page. Most recent reply: Apr 14, 2003 3:01 AM by Adam Duffy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Joe

Posts: 5
Nickname: tiger19
Registered: Apr, 2003

determining mulitples Posted: Apr 12, 2003 7:20 PM
Reply to this message Reply
Advertisement
I need to test whether numbers ranging from 2 to 100 are multiples of 2,3,4, or 5 using a "for statement". Anyone got any ideas, hints, etc.?


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: determining mulitples Posted: Apr 12, 2003 7:59 PM
Reply to this message Reply
for (int i =  2; i < = 100; i++){
 if (i%2 == 0) System.out.println(i + "is a multiple of 2.");
if (i%3 == 0) System.out.println(i + "is a multiple of 3.");
if (i%4 == 0) System.out.println(i + "is a multiple of 4.");
if (i%5 == 0) System.out.println(i + "is a multiple of 5.");
}

Joe

Posts: 5
Nickname: tiger19
Registered: Apr, 2003

Re: determining mulitples Posted: Apr 12, 2003 8:24 PM
Reply to this message Reply
thanks again

Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: determining mulitples Posted: Apr 14, 2003 3:01 AM
Reply to this message Reply
Hmm. See topic titled testing range.

I thought I already answered this question for Joe.... Oh well.

Adam

Flat View: This topic has 3 replies on 1 page
Topic: Urgent Problem on GUI Previous Topic   Next Topic Topic: explorer dsn by java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use