Author |
Message |
xX_MayDay_Xx
|
Posted: Tue Mar 07, 2006 8:32 am Post subject: Multiples |
|
|
ok...time for another harrasing the N()()b session...
Im having trouble using Multiples, i cant fiqure out how to break the number,....basically i have no idea what the hell i am doing. i have to write a program that takes two numbers input by the user and check to see if they are mutliples of eachother......i know im the biggest noob in the world when it comes to this stuff, so if you could explain it in a peacefull simple manner that doesn't invole calling me a retard, i will be greatfull for your help. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
xX_MayDay_Xx
|
Posted: Tue Mar 07, 2006 7:15 pm Post subject: (No subject) |
|
|
A Multiple is any number that you Multiply to get another number.....example, 3 is a multiple of 6 because (2*3=6)...or
4 is a multiple of 20 because (4*5=20)
and i have another question, i downloaded Text,Pad so i can work on my programes at home it works and everything except for one problem....everytime i try to run or compile a program a messege comes up and say..."The system cannot find the file specified"...anbd the message comes from "C:\WINDOWS\System32\javac.exe".....does anyone know how to fix that |
|
|
|
|
|
wtd
|
Posted: Tue Mar 07, 2006 8:05 pm Post subject: (No subject) |
|
|
How would you determine if 6 is a multiple of 2? |
|
|
|
|
|
Justin_
|
Posted: Tue Mar 07, 2006 8:27 pm Post subject: (No subject) |
|
|
Well here's a nice introduction to modulus. Although you don't even need modulus really, you could just divide the number you are trying to determine is a multiple by the number and if it comes out as a whole number you know that it is a multiple.
But the way i would do it is with modulus. Modulus is a mathematical operator that outputs the remainder of a division question. That's it, just the remainder.
The modulus symbol is %.
4%20 = 0
4%4 = 0
4%5 = 1 |
|
|
|
|
|
xX_MayDay_Xx
|
Posted: Wed Mar 08, 2006 8:22 am Post subject: (No subject) |
|
|
ok ill try the divison thing,.... and as to the hoe would you dertimine if 6 is a multiple of 2, i have absoulutly no clue. |
|
|
|
|
|
Martin
|
Posted: Wed Mar 08, 2006 7:41 pm Post subject: (No subject) |
|
|
People have to be taught, not ridiculed. I'm a math major and guess what? I'm probably a hell of a lot better at math than most people on these boards. So does that mean that nobody should be allowed to ask questions under, say, a second year university level?
I don't know about you guys, but I wasn't born with a knowledge of integrals, but I know a lot about integral calculus now. This wasn't because my teacher told me I was stupid for not knowing it. Education is not supposed to be a hostile environment.
This guy asked a question that we all know the answer to, yet suprisingly nobody's given him an answer. The reason that we're here is to help people, and if you don't want to do that either be quiet or go somewhere else.
That said, I'm deleting these innappropriate posts (and some of Justin_'s posts, because they didn't make sense anymore). |
|
|
|
|
|
wtd
|
Posted: Wed Mar 08, 2006 7:47 pm Post subject: (No subject) |
|
|
It's my opinion that many people know more than they realize. I answer questions with questions in many cases because I want to help people realize that they already know the answer. |
|
|
|
|
|
Martin
|
Posted: Wed Mar 08, 2006 7:50 pm Post subject: (No subject) |
|
|
wtd wrote: It's my opinion that many people know more than they realize. I answer questions with questions in many cases because I want to help people realize that they already know the answer.
Sorry, my above post wasn't directed at you, but at the people who were telling him "he shouldn't be programming" because he didn't know how to do this (I deleted the posts) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Martin
|
Posted: Wed Mar 08, 2006 7:54 pm Post subject: (No subject) |
|
|
To expand on wtd's question - we know that 6 is a multiple of 3, but that 7 is not a multiple of 3. Why and why not? If I were to give you two numbers, how would you go about determining if one was a multiple of the other? |
|
|
|
|
|
rizzix
|
Posted: Wed Mar 08, 2006 8:17 pm Post subject: (No subject) |
|
|
Straight to the point: if the remainder of n / m is zilch (i.e no remainder) then n is a direct (integral?) multiple of m.
easy way to test this is using the modulus operator: n % m == 0 or (bitwise style) n & (m - 1) == 0
The latter form involves more operations than the former. It is not recommended as it can be slower. |
|
|
|
|
|
xX_MayDay_Xx
|
Posted: Fri Mar 10, 2006 8:48 am Post subject: (No subject) |
|
|
um ok...i have made some progress in my code....i know that my code can be very hard to read but bare with me....it work's for the most part But it will always go to the first if statement...
code: | public class Multiple
{
public static void main (String[]args)
{
int num;
int num2;
int var;
System.out.println("plz input two number");
num=In.getInt();
num2=In.getInt();
var=num%num2;
if (var>0){
System.out.println("this is not a multiple");
}
else{
System.out.println("this is a multiple");
}
}
} |
|
|
|
|
|
|
Justin_
|
Posted: Fri Mar 10, 2006 12:42 pm Post subject: (No subject) |
|
|
What import allows you to use In.getInt()? I'm pretty new myself so I really don't know.
As for your code it's better to write:
if (number != 0)
the != operator means "does not equal". |
|
|
|
|
|
Justin_
|
Posted: Fri Mar 10, 2006 12:53 pm Post subject: (No subject) |
|
|
This works.
Java: |
import java.io.*;
import java.util.*;
public class Multiple
{
public static void main (String[]args )
{
int num;
int num2;
int var;
System. out. println("plz input two number");
num = In. getInt();
num2= In. getInt();
var = num2 % num;
if (var != 0)
{
System. out. println("the 1st num is not multiple of the 2nd num");
}
else
{
System. out. println("1st num is a multiple of 2nd num");
}
}
}
class In
{
static BufferedReader br = null;
static int getInt ()
{
if(br == null)
br = new BufferedReader(
new InputStreamReader(System. in));
int n = - 1;
try
{
String line = br. readLine();
n = Integer. parseInt(line );
}
catch(IOException ioe )
{
System. err. println("read error: " + ioe. getMessage());
}
return n;
}
}
|
|
|
|
|
|
|
|