LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-06-2007, 02:04 PM   #1
freakyg
Member
 
Registered: Apr 2005
Distribution: LFS 5.0 and 6.1
Posts: 705

Rep: Reputation: 30
Java Modulus operator


First of all this is not homework, I saw this on another forum and it looked interesting. I managed to program this out in Java but I'm having a hard time converting it to javascript and/or perl...can you give me a hand please.....

Quote:
First create a variable called total (int initialised to 0),
then write a loop which counts a variable (int loopCounter) from 0 to 1013.

Within the loop block the following needs to be performed:
1) the total must be updated by adding 2*loopCounter to the total.
2) Then loopCounter%3 must be added to the total. (% is Java for modulus).
thanks much
 
Old 06-06-2007, 02:25 PM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
With what are you having problems?

I don't want to just post a solution, without giving you a real helping hand, but I've written one in Perl if you want it.
 
Old 06-06-2007, 02:52 PM   #3
freakyg
Member
 
Registered: Apr 2005
Distribution: LFS 5.0 and 6.1
Posts: 705

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by taylor_venable
, but I've written one in Perl if you want it.

if you would please, I just figured it out in javascript somewhat, just gotta tweak it a little and I'll post for others to check out. thx
 
Old 06-06-2007, 10:06 PM   #4
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Code:
use warnings;
use strict;

my $total = 0;
foreach my $loopCounter (0 .. 1013) {
    $total += 2 * $loopCounter;
    $total += $loopCounter % 3;
}

print $total;
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java...operator overloading question arunvk Programming 6 03-23-2006 07:31 AM
bc: using -l messes up modulus Ephracis Programming 4 06-07-2005 01:34 PM
Divisibility without using modulus redhatrosh Programming 1 03-01-2005 10:02 PM
Modulus in Assembly How? browneyes Programming 2 10-07-2004 12:42 PM
Operator Overloading - Java? Tesl Programming 4 02-13-2004 12:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration