• Welcome to Valhalla Legends Archive.
 

Java Help :(

Started by WinSocks, February 25, 2003, 12:25 PM

Previous topic - Next topic

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....

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 );
    }
}

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:
if ( num1 < num2 )
   Result = Result + "\n" + num1 + " < " + num2;
if ( num1 > num2 )
   Result = Result + "\n" + num1 + " > " + num2;

any help will be appreciated..        

iago

#1
import java.lang.Math;
...
println("Max of a, b, and c is" + Math.max(Math.max(a, b), c));
...
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Tuberload

#2
You do not have to import anything from the java.lang package because it is automatically loaded into all Java programs.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

iago

#3
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 :(
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Banana fanna fo fanna

#4
Some compilers issue a warning for some gay reason (cough cough j++)

iago

#5
Probably because it's not part of the standardization that Java is so famous for.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Banana fanna fo fanna

#6
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.

iago

#7
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!
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Banana fanna fo fanna

#8
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 ;)

Tuberload

#9
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.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

Banana fanna fo fanna

#10
Nah, JITs just native compile programs temporarily in-memory.

Tuberload

#11
Thats right, thanks for the reminder.

It would make the program run faster once loaded then wouldnt it?
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

Banana fanna fo fanna

#12
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.