473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

if conditions, 2 numbers equal

so I have 2 different variables, int a and double b

I tried to do

if ( a = b ) {
Condition
}

But that doesn't work, and I'm not sure if a==b is the same thing.

It's a program where I need to do stuff with 2 numbers, and need to find out if the result is an integer, then print it if it's an integer.

so since int's ignore decimals and doubles don't, i set them equal so unless b is a whole number, it won't equal.

Sorry I'm new to java, I can't figure out hwo to check if a number is an integer, and nothing too complex that we haven't learned, because this is an assignment for class.

Thanks!
Nov 9 '08 #1
3 2328
JosAH
11,448 Expert 8TB
The operators '=' (one equals sign) and '==' (two equals signs) are definitely different.
The first one assigns the value of the right hand side to the left hand side. The other
operator compares both operands for equality and returns true or false, depending
on the equality.

About your question: have a look at the Math.rint(double x) method; it returns
an integer value closest to its operand x, so if x == Math.rint(x) is true the value
x represents an integer value.

kind regards,

Jos
Nov 9 '08 #2
Actually, I just realized I need 2 methods for this assignment, I need the user to input 2 integers and it finds the least common denominator of the 2 digits and prints it.

I don't really want the actually code, but I don't really understand the whole concept of how to use 2 methods.

I originally planned on multiplying a input by a loop++; until it reaches a number input 2 can divide it so that it is an integer.

Any help? =]

Thanks~!
Nov 9 '08 #3
JosAH
11,448 Expert 8TB
Any help?
Not from me because your description doesn't make sense to me at all.

kind regards,

Jos
Nov 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

89
by: purifier | last post by:
The problem is to write a program in 'C' to find the greatest of 2 given numbers... Easy? huh here's the catch do not use 'if' or any conditional statements if u want it to be a little more...
65
by: PengYu.UT | last post by:
Hi, Sometimes, I write = instead of == in if conditions by mistakes. Is there any way the gcc compiler can give me a warning? Best wishes, Peng
2
by: Rich | last post by:
Here is what I am trying for randomizing 2 numbers in the same subroutine so that they are not equal to each other: Dim j As Integer, k As Integer j = New System.Random().Next(0, 10) k = New...
5
by: jacob.dba | last post by:
I have a table with first name, last name, SSN(social security number) and other columns. I want to assign group number according to this business logic. 1. Records with equal SSN and (similar...
11
by: balakrishnan.dinesh | last post by:
hi frnds, Im having two 20digit numbers, But while comparing those it is giiving wrong ouput in javascript. for example here is my code, my secanrio is , ~ If first 20 digit number is...
10
by: greedo | last post by:
Hi, first of all, please bear with me, I don't really know a great deal about php programming, as will be painfully obvious from the code snippet I'm gonna post. But I need this problem solved, and...
8
by: kiranchahar | last post by:
Hey all, How do I generate random numbers with Uniform distribution Uniform(a,b) using C-programming? I want to generate uniform random numbers which have mean following Uniform(p,q) and also...
5
by: ariel ledesma | last post by:
Christian Heimes wrote: i see now, so i guess that's also why id() returns the same address for them as well... i'll dive into the implementation file, it may be a bit out of my league but i'll...
5
by: anumliaqat | last post by:
hello!! i hav a problem.my program is giving correct outputs for some inputs but wrong results for others. for example if u give (4 2 2)&(2 1 2) to it,it shows all results correct....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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,...
0
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...

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.