View Full Version : A Hard Question
p4pex33
01-26-2010, 01:57 PM
This is our assignment, and i would like to share it to fellow Otaku's
(I don't know the answer yet)
what is the scientifical or mathematical explanation that 2 is greater than 1?
AND for programmers:
the Problem is ask 2 numbers from a user, and then determine what is the greatest number without using Relational & Mathematical Operation... using JAVA or c++.. :)
darkpoetry
01-26-2010, 03:09 PM
which computer language are you refering to?
In java you can use the .compare() method, make a Comparator class.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html
For the first part I think it would fall under Number Theory. Thats some crazy stuff that my major doesn't require so I never took it before.
p4pex33
01-26-2010, 03:40 PM
@darkpoetry
thx.. but can you give me a simple code on how to use the .compare() method?
in youre link i tried this
int compare(Object o1, Object o2)
but what is that? a variable or a method? and if it's a method what's the return type?
and do i need some imports in order for this to work?
THX allot
"No programmer can stand alone when it comes to programing"
darkpoetry
01-26-2010, 05:35 PM
Scratch that, seems like you just started.
In order to use the compare method you need to make a instance of the comparator which will probably be a bit confusing to you.
Also the return type will the difference of the two so you may still need to use a logic opperator.
Ok, heres something a much more simple.
I'm sure you've worked with arrays, right?
Import java.util.Arrays;
Put the two numbers into the array
theArray[0] = firstNumber;
theArray[1] = secondNumber;
Arrays.sort( theArray );
pretty sure the smaller of the two will be in Array[0] and the larger will be in Array[1]
EDIT: I'll just write it, must clearer than explaining
public static void main(String[] args) {
int[] theArray = new int[2];
//creates an array of size 2 which holds integers (you can use floats or double or whatever)
theArray[0] = 10;
theArray[1] = 3;
//puts the first number in index 0 and the second number index 1
Arrays.sort(theArray);
//sorts the array
System.out.println("The Smaller Number is: " + theArray[0]);
System.out.println("The Larger Number is: " + theArray[1]);
//prints the results
}
RESULT:
The Smaller Number is: 3
The Larger Number is: 10
p4pex33
01-27-2010, 03:37 PM
@dark
well the program satisfies the problem... but how did the Arrays.sort , sorted the numbers? what are the operations or etc. behind Arrays.sort so that the outcome is correct?
darkpoetry
01-27-2010, 08:57 PM
Arrays is a class in itself that is given by java
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html
So instead of making a class which does the sorting, you use one that java provided
You can just google "java arrays" and you will come to the java sun website which explains in plain words what the class is for and what each method does (but you will need to know some of the basic terminology)
.sort is simply a method within the class
if you scroll down you will see what method we used Array.sort(int[])
The website explains that the method uses a way called "quick sort" which is pretty hard to explain... but its known as one of the fastest methods
http://en.wikipedia.org/wiki/Quicksort
I learned this method in a Data Structures course so I am sure your teacher will not expect you to know how it works.
However, within the method uses logical operations in itself
OVirus53
01-28-2010, 10:31 AM
Here's an explanation: You have one great martial artist on one side, who can beat any martial artist one on one. WAPOW! So, two great martial artists think "hey, if we team up, we might stand a chance!" Then they teamed up and beat the one great martial artist. WATATATATATATATATATA! Thus proving that two great martial artists are greater than the one.
O_O is it late? Did this really escape from my brain?
jeiru01
02-05-2010, 11:32 AM
I'll answer the question about 2 and 1..
all the numbers in the left are lesser than those in the right.
it's obvious that number 2 is in the right. so that means,
It's greater than the one in the left: 1.
nannel24
02-05-2010, 12:00 PM
I'll answer the question about 2 and 1..
all the numbers in the left are lesser than those in the right.
it's obvious that number 2 is in the right. so that means,
It's greater than the one in the left: 1.
yeah right..
mizuki538
02-05-2010, 01:10 PM
about 2 and 1:
2 is greater then simply b'coz 1 is less than 2..
well 1 is less than 2... COZ 2 IS GREATER THAN 1...
erikachan
02-06-2010, 03:21 AM
about 2 and 1:
2 is greater then simply b'coz 1 is less than 2..
well 1 is less than 2... COZ 2 IS GREATER THAN 1...
hahaha... you nailed it!
pidodido
02-09-2010, 07:15 PM
I'll answer the question about 2 and 1..
all the numbers in the left are lesser than those in the right.
it's obvious that number 2 is in the right. so that means,
It's greater than the one in the left: 1.
WOW you have talent.......
hahahahahah
Powered by vBulletin™ Version 4.0.8 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.