473,883 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java math help needed


I need to recreate the following formula in java:

INT((A2^3 + B2^3) / 100)) + MOD((A2^3 + B2^2), 100)

Can someone show me how to do this in java?
-Thanks

Jul 17 '05 #1
4 21766
Fred wrote:
I need to recreate the following formula in java:

INT((A2^3 + B2^3) / 100)) + MOD((A2^3 + B2^2), 100)

Can someone show me how to do this in java?
-Thanks


What do you mean by int? you mean integrate or what?

Mod is % in java. so int i = 10 %5 = 0. 11 % 5 = 1 (if i remember
correctly)

To do powers you simply do Math.pow() look it up in your java api docs.
Look for the Math class.

Jul 17 '05 #2
int answer = ((int)(pow(a2,3 ) + pow(b2,3)) / 100) +
((pow(a2,3) + pow(b2,2)) % 100);
Fred <it****@cdw.com > wrote in message news:<pa******* *************** ******@cdw.com> ...
I need to recreate the following formula in java:

INT((A2^3 + B2^3) / 100)) + MOD((A2^3 + B2^2), 100)

Can someone show me how to do this in java?
-Thanks

Jul 17 '05 #3
All you need to do is to spend 10 mins reading your textbook, rather than
posting your homework and waiting somebody to do it for you.

HD
"Fred" <it****@cdw.com > wrote in message
news:pa******** *************** *****@cdw.com.. .

I need to recreate the following formula in java:

INT((A2^3 + B2^3) / 100)) + MOD((A2^3 + B2^2), 100)

Can someone show me how to do this in java?
-Thanks

Jul 17 '05 #4
"Yoyoma_2" wrote:
Fred wrote:
I need to recreate the following formula in java:

INT((A2^3 + B2^3) / 100)) + MOD((A2^3 + B2^2), 100)

Can someone show me how to do this in java?
-Thanks

What do you mean by int? you mean integrate or what?

Mod is % in java. so int i = 10 %5 = 0. 11 % 5 = 1 (if i remember
correctly)


Nitpick:

% in Java is actually remainder, not Modulus.
True Modulus produces a result from 0 to the divisor-1.
% can produce negative results.

"the % operator is not a true mod operator, but computes the remainder,
which may be negative"
http://java.sun.com/docs/books/jls/assert-spec.html
To do powers you simply do Math.pow() look it up in your java api docs.
Look for the Math class.

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
1624
by: Lloyd Dupont | last post by:
here a little test program. it's so simple taht it should deliver simmilar result. it's also so simple that people that might says it's unfair to the looser (why Java people are always arguing like that ?)... anyway see for yourself the test command lines: javac SimplePerf.java && java SimplePerf 10000000 csc /nologo SimplePerf.cs && SimplePerf 10000000
33
9964
by: patrick_woflian | last post by:
hey guys, im just writing a basic calculation at the moment, before building on it for an A-Level piece of work. i can add/divide etc... two numbers together yet i am having a major problem with the following calculation: z = x! / (x- y)! The following code is my attempt and i was hoping for a point in the right direction as too where i am going wrong.. cheers
1
9672
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
36
2116
by: Robert Baer | last post by:
I used Google and found some references for integer in Java. But "int" not only does not work, it also prevents reading X and Y coordinates of the mouse. What i would like to do: 1) Get X and Y mouse coordinates into a variable that i can do real math on. So far, i can do math on the values "read" and that result goes into a "variable" that is useful *only* for display. If i try "int" in that math, the values are then zero for everything...
2
7896
by: phjones | last post by:
Need help programming mortagage calculator for 3 different loans 7 year, 15 year and 30 year. using java array I am a beginner with Java, This is what I have so far. Need to know if I am off the path, import java.math.*;//*loan calculator import java.text.*;//*formats numbers public class 3 Mortgage loans { // declare class variable array int mortgage calculator
2
1447
by: dragonball | last post by:
hi, i want to use log(double) in my java prog. so i have imported java.lang.Math flanagan.math.PsRandom now i wanna use log function in a private method inside a class. so i try : return (94.2)-(0.024*avg_playout_delay)-11-(40*log(1+10*avg_playout_delay));
1
3305
by: feathers75 | last post by:
-------------------------------------------------------------------------------- First, Hello eveyone and I am new to Java. I am trying to create a Java program that will calculate a person BMI based on user input of weight (in pounds) and heigh (in inches) and then display what the BMI is and give the a message that tells them where they fit plus I want to then be able to tell them how much weight they need to loss (or gain if...
5
6304
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is JDK 6 downloadable from http://java.sun.com/javase/downloads/index.jsp. I will be using JDK 5(update 8)
0
9942
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10745
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10848
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10417
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9575
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7972
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5798
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.