Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com modulus % as a relational operator

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 12-02-2010, 07:53 PM PM User | #1 mariemac New to the CF scene   Join Date: Nov 2010 Posts: 2 Thanks: 1 Thanked 0 Times in 0 Posts modulus % as a relational operator Being triyng to get my head around a use for the modulus operator % and where it can be used . It was suggested that it can be used in evaluating a statement in a if else loop Code: ``` if (int % 6 == 0) { do this else do that .``` as someone who has never come across the modulus operator before can someone explain how this works and if it is possible to code the same test without using the modulus . much obliged for any input on this
 12-02-2010, 08:38 PM PM User | #2 cs_student Regular Coder     Join Date: Oct 2009 Location: ~/ Posts: 195 Thanks: 2 Thanked 22 Times in 22 Posts The modulus thing can be used in many different ways. You can generally do it other ways (though it may not be as intuitive or easy). ie, if you want to see if something is even or odd. Using the mod operator Code: ```int x = 193586 if(x % 2 == 0) System.out.println("Even"); else System.out.println("Odd");``` You could also create a recursive method that would determine. (I just came up with this off the top of my head so it might not work quite right). Code: ```public boolean even(int num, int current) { if(current > num) return false; else if(current == num) return true; else return even(num, current * 2); } System.out.println(even(193586, 2));``` While you can certainly do things differently, it is generally easier to use the modulus operator. __________________ Get GNU/Linux - Play Ogg - Vim Using Arch Linux x86_64, Xorg + xmonad
 Users who have thanked cs_student for this post: mariemac (12-03-2010)

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 05:10 PM.