Author | Message | Time |
---|---|---|
WinSocks | I been working on a project and i'm new to Java 2.0 programming.... i have to make a application that asks for the user to input 3 intigers and then the application will calculate the sum, product, average and the Largest/Smallest integer from the three... i got everythign but the damn smallest/largest method.... [code] import javax.swing.JOptionPane; public class threeint { public static void main( String args[] ) { String firstNumber; String secondNumber; String thirdNumber; String Result; int num1; int num2; int num3; int Sum; int Average; int Product; firstNumber = JOptionPane.showInputDialog( "Enter frist integer:" ); secondNumber = JOptionPane.showInputDialog( "Enter second integer:" ); thirdNumber = JOptionPane.showInputDialog( "Enter frist integer:" ); num1 = Integer.parseInt( firstNumber ); num2 = Integer.parseInt( secondNumber ); num3 = Integer.parseInt( thirdNumber ); Sum = num1 + num2 + num3; Product = num1 * num2 * num3; Average = Sum / 3; Result = ""; if ( num1 < num2 ) Result = Result + "\n" + num1 + " < " + num2; if ( num1 > num2 ) Result = Result + "\n" + num1 + " > " + num2; JOptionPane.showMessageDialog( null, "The Sum: " + Sum + "\nThe Average: " + Average + "\nThe Product:" + Product + "\nThe Largest/Smallest Integer: " + Result, "Integer Excercise", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } } [/code] i been trying to figure out how to get the application or find the code for a if statement that takes all 3 integers and calculates what is the largest and smallest. has to do with the code: [code] if ( num1 < num2 ) Result = Result + "\n" + num1 + " < " + num2; if ( num1 > num2 ) Result = Result + "\n" + num1 + " > " + num2; [/code] any help will be appreciated.. | February 25, 2003, 6:25 PM |
iago | [code] import java.lang.Math; ... println("Max of a, b, and c is" + Math.max(Math.max(a, b), c)); ... [/code] | February 25, 2003, 8:14 PM |
Tuberload | You do not have to import anything from the java.lang package because it is automatically loaded into all Java programs. | February 26, 2003, 12:42 PM |
iago | I just followed the instructions from java.sun.com, but either way it doesn't hurt to, maybe on some builds it's not automagic. I would test it on my school's linux machine, but it's down :( | February 26, 2003, 3:56 PM |
St0rm.iD | Some compilers issue a warning for some gay reason (cough cough j++) | February 26, 2003, 4:48 PM |
iago | Probably because it's not part of the standardization that Java is so famous for. | February 26, 2003, 4:49 PM |
St0rm.iD | Yeah :( Java is a good language, but the politics and marketting suck. For example, IBM makes the best Java compiler, jikes, and no one uses it, because people think that the Sun JDK is the only way to go. People also think Java sucks because it's slow. Well, in reality, Sun's JVM is slow. Other JVMs are much faster, some even compile to .exe files. | February 26, 2003, 9:31 PM |
iago | Doesn't compiling to a .exe file defeat the purpose? It would only run on the target platform, no? I heard about a JVM that converts the program to the native code on load, and runs that. I couldn't see that being any slower than normal machine code. The reason I don't like Java (and yes, I've used it enough to form opinions for real, now!), is the same reason I don't like VB: I feel like my hands are tied behind my back. I don't get the freedom I like to do stupid things like c++ lets me do. Void pointers, for instance, or direct memory access. And don't get me started on strings! | February 26, 2003, 10:07 PM |
St0rm.iD | Thing I don't like about Java is the fucking politics, buzzwords, stupid Sun controlling it so much, stupid Sun fucking the VM versions, and finally, on top of it all........ SWING FUCKIN SUCKS! 'Nuff said. Everything else is nice ;) | February 26, 2003, 11:10 PM |
Tuberload | I believe just as a standard the java.lang will be loaded automatically into any program despite what VM you are using because it contains the general purpose classes, System, Math, etc... Don't quote me on that because I am by no means an expert but that is what my learning experience has been over the past year. Although you can quote me that using Suns VM you do not need to load it, I couldn't tell you about IBM's, or any other for that matter. The rest is just my opinions on comments within this thread; read only if you want to continue this discussion. Java was also not created to do the same things as C++. It's been developed for portable use over the internet, i.e. applets. With that to work you need it to be interpreted, so naturally you sacrifice some speed. Though the bytecode used is much faster than any other interpreted language, so not to terribly much speed is lost. I personally believe if you are trying to create universally portable programs, or have a need for applets/servlets, or you need to program a toaster, what Java was originally made for, then Java is a good language. If you are creating computer dependent programs or need access to things restricted by Java do to security use C++. Java and C++ will coincide for years. Java was not created to replace anything. JIT is a compiler I know of that converts it to native code, and yes it makes it system dependent and does defeat the purpose of Java. | February 27, 2003, 12:50 PM |
St0rm.iD | Nah, JITs just native compile programs temporarily in-memory. | February 27, 2003, 6:32 PM |
Tuberload | Thats right, thanks for the reminder. It would make the program run faster once loaded then wouldnt it? | February 28, 2003, 1:19 PM |
St0rm.iD | Sort of. Actually, they inline/compile functions after they've run a few times...so programs start slow and gradually speed up. However, it's not saved...so you lose the native compilation after it executes. | February 28, 2003, 6:58 PM |