Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

"times 2" in Java?

Name: Anonymous 2009-04-11 18:16

import static java.lang.System.out;
public class Times2 {
  public static void main(final String[] args) {
    for (byte i = 1; i < 11; i++) {
      out.println(2 + " x " + i + " = " + 2 * i);
    }
  }
}


public class Times2 {
  public static void main(final String[] args) {
    for (byte i = 1; i < 11; i++) {
      System.out.println(2 + " x " + i + " = " + 2 * i);
    }
  }
}


Am I ENTERPRISE enough?

Name: Anonymous 2009-04-11 18:29

>>1
NEEDS MOAR FACTORIES!!!!!!!!!1

Name: Anonymous 2009-04-11 18:34

Use BigIntegers.

Name: Anonymous 2009-04-11 19:50

This is a horrible excuse for an enterprise application. The fact you have to enter "2 *|x i" twice is creating duplicate code that makes your program difficult to maintain. I recommend using reflection to build a method at runtime so you only need to specify the operator and operand once.

Name: Anonymous 2009-04-11 23:38

Paradoxically, writing good ENTERPRISE parody code does require that you have more than a passing acquaintance with Java. Why don't you try again at the end of your first semester?

Name: Anonymous 2009-04-12 3:27

>>1
final String[] args
Ahahaha... hahaha... haha... ha.

Name: Anonymous 2009-04-12 3:28

>>4
Stack pointer monadic overflow. what now fag.

Name: Anonymous 2009-04-12 3:38

>>7
Yo momma's so fat she sat on a binary tree and turned it into a linked list in constant time!

Name: Anonymous 2009-04-12 5:59

>import static
When the fuck did Java get this?

Name: Anonymous 2009-04-12 6:20

I agree with >>5.

Name: Anonymous 2009-04-12 11:57

>>9
Java 1.5. Or Java ``5'', as it's also called.

Name: Anonymous 2009-04-13 6:39

>>4
There is no duplicate code.
I just posted 2 versions of the same class.

Name: Anonymous 2009-04-13 6:42

>>12
And you duplicated your arithmetic expression in each of them.  lrn2read.

Name: Anonymous 2009-04-13 9:51

If you want to make it in an enterprise environment you have to create scalable solutions OP. What happens if you want to change your code to divide instead, you are going to have to go through and change all instances of multiplication with division which in some cases may become impractical. Me being a nice person, have created you an examplar from which you will be able to observe techniques for creating a scalable solution. NB: If the programmer now in hindsight wishes to change the operation to division say, all he needs to do is change a string constant at the start to a division sign. Likewise for arbitrary complex equations. You may wish to try,
    private static final String OPERATOR = "* -14 /";
    private static final String OPERATORPRINT = OPERATOR;
    private static final String OPERAND = "java.lang.Math.PI";


import java.io.*;
import java.lang.reflect.*;
public class TimesTwo extends ClassLoader {
    private static final String DYNAMICFILE = "TimesTwoDynamic.java";
    private static final String DYNAMICMETHOD = "printArithmetic";
    private static final String OPERATOR = "*";
    private static final String OPERATORPRINT = "x";
    private static final String OPERAND = "2";
    private static final int START = 0;
    private static final int STOP = 10;
    private static final int INCREMENT = 1;
    public static void main(String[] args) throws Exception {
        PrintWriter pw = new PrintWriter(new FileWriter(DYNAMICFILE));
        String noExtName = DYNAMICFILE.substring(0, DYNAMICFILE.lastIndexOf("."));
        writeArithmeticCode(pw, noExtName, DYNAMICMETHOD, OPERATOR, OPERAND, OPERATORPRINT, START, STOP, INCREMENT);
        compileClass(DYNAMICFILE);
        loadAndExecuteMethod(noExtName, DYNAMICMETHOD);
    }
    public static void compileClass(String sourceFile) throws Exception {
        Runtime.getRuntime().exec("javac "+sourceFile).waitFor();
    }
    public static void writeArithmeticCode(PrintWriter pw, String className, String methodName, String operator,
                                            String operand, String printableOperator, int min, int max, int step) throws IOException {
        pw.write("public class "+className+" {\n" +
            "\tpublic static void "+methodName+"() {\n");
        for(int i=min; i<=max; i+=step)
            pw.write("\t\tSystem.out.println("+operand+" + \" "+printableOperator+" \" + "+i+" + \" = \" + ("+operand+" "+operator+" "+i+"));\n");
        pw.write("\t}\n");
        pw.write("}");
        pw.close();
    }
    public static void loadAndExecuteMethod(String className, String methodName) throws Exception {
        Class c = (new TimesTwo()).loadClass(className, true);
        Method m = c.getMethod(methodName, (Class[])null);
        m.invoke(null, (Object[])null);
    }
    public Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
        Class newClass = null;
        File classFile = new File(name.replace('.','/')+".class");
        byte[] bytes = new byte[(int)classFile.length()];
        try {
            FileInputStream fis = new FileInputStream(classFile);
            fis.read(bytes);
            fis.close();
            newClass = defineClass(name, bytes, 0, bytes.length);
        }
        catch(IOException e) {
            newClass = findSystemClass(name);
        }
        if(resolve) resolveClass(newClass);
        return newClass;
    }
}

Name: Anonymous 2009-04-13 9:58

>>14
Doesn't look very scalable to me. You should create an Operator class so that it is possible to separate the external presentation of an operator from its semantics, and then possibly an OperatorFactory to ease Operator creation.

Name: Anonymous 2009-04-13 10:02

>>15
Excellent observation, sadly I don't wish to waste time writing code where the idioms used are already committed to memory. I'll leave that as an excercise to the OP.

Name: Anonymous 2009-04-13 10:13

>>14-16
*grabs dick*

Name: Anonymous 2009-04-13 18:41

OP here.

Fuck



me.

Name: Anonymous 2009-04-13 21:13

Fuck me, does 14 actually WORK?

I haven't written serious java code in about 4 years so i have no idea what the fuck they've done to the language since. Hell, I remember when Swing was the new hotness.

Name: Anonymous 2009-04-13 21:14

>>19
Back, villian, or I will break thy pate across!

Name: Anonymous 2009-04-13 21:41

>>14
One of the best ENTERPRISE programs I have ever seen on /prog/!

Name: Anonymous 2009-04-14 7:23

>>19
Compiles with one warning and runs. If someone knows how to get that warning to fuck off without using @suppress, feel free to let me know.

Name: Anonymous 2009-04-16 7:15

Exeunt

Name: Anonymous 2009-04-16 7:20

>>23
Back, villian, or I will sage thy pate across

Name: Anonymous 2009-04-16 7:27

>>25
 If you bother him, in's tale, one more time, with this hand I shall supplant some of your teeth.

Name: Trollbot9000 2009-07-01 11:04

Actually make it work I mean this  shit is complicated.

Name: Anonymous 2009-07-02 1:01

>>4
I recommend using reflection to build a method at runtime
This is impossible. Java does not support adding methods at runtime.

Name: FrozenVoid 2009-07-02 1:56

>>27 Unlike JavaScript.



_________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
In the long run the sword is always beaten by the spirit.

Name: Anonymous 2009-07-02 3:04

>>27
See >>14

Name: Anonymous 2009-07-02 7:26

>>29
Then C supports adding functions on runtime too. Whodathunkit?

Name: Anonymous 2009-07-02 8:07

>>30
Well, C support adding functions at runtime anyway because of how much control you get over memory. If you ignore small implementation defined things such as the size of an integer in the standard, you can pretty well write a function into memory yourself at runtime and have it port to any major platform. Your argument fails anyway, because Java actually can add methods at runtime. You don't actually have to use an external compiler, you could write your own into the program so that it can translate your code into bytecode on the fly, and then use a class loader. I really don't see where your argument is coming from.

Name: Anonymous 2009-07-02 8:16

>>12
data:text/html;base64,PCFET0NUWVBFIGh0bWw+PGh0bWw+PGhlYWQ+PHRpdGxlPnNob3VsZCBpIHVzZSBzYWdlPzwvdGl0bGU+PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPmZ1bmN0aW9uIGEoKXtmdW5jdGlvbiBjKGkpe3JldHVybiBkb2N1bWVudC5nZXRFbGVtZW50QnlJZChpKS5jaGVja2VkfWFsZXJ0KGMoJ3ExJyl8fGMoJ3EyJyl8fGMoJ3EzJyl8fGMoJ3E0Jyl8fGMoJ3E1Jyl8fGMoJ3E2Jyl8fGMoJ3E3Jyk/J3llcyc6J25vJyk7cmV0dXJuIGZhbHNlfTwvc2NyaXB0PjwvaGVhZD48Ym9keT48Zm9ybSBpZD0icXVlc3Rpb25zIiBvbnN1Ym1pdD0iYSgpIj48b2w+PGxpPjxpbnB1dCB0eXBlPSJjaGVja2JveCIgaWQ9InExIiBjaGVja2VkPSJjaGVja2VkIj4gbXkgcG9zdCBpcyBzcGFtLjwvbGk+PGxpPjxpbnB1dCB0eXBlPSJjaGVja2JveCIgaWQ9InEyIiBjaGVja2VkPSJjaGVja2VkIj4gbXkgcG9zdCBpcyBhYm91dCBzb21ldGhpbmcgbWVudGlvbmVkIGluIHNvbWUgb3RoZXIgcG9zdCBpbiB0aGUgdGhyZWFkLjwvbGk+PGxpPjxpbnB1dCB0eXBlPSJjaGVja2JveCIgaWQ9InEzIiBjaGVja2VkPSJjaGVja2VkIj4gbXkgcG9zdCBjb250YWlucyBhdCBsZWFzdCBvbmUgbWVtZSBmcm9tIC9iLywgL2cvLCAvbG91bmdlLCBvciA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GVja2JveCIgaWQ9InE0IiBjaGVja2VkPSJjaGVja2VkIj4gaSBhbSBwb3N0aW5nIHdpdGggYSBuYW1lLjwvbGk+PGxpPjxpbnB1dCB0eXBlPSJjaGVja2JveCIgaWQ9InE1IiBjaGVja2VkPSJjaGVja2VkIj4gaSBhbSBwb3N0aW5nIHdpdGggYSB0cmlwY29kZS48L2xpPjxsaT48aW5wdXQgdHlwZT0iY2hlY2tib3giIGlkPSJxNiIgY2hlY2tlZD0iY2hlY2tlZCI+IHRoZSB0aHJlYWQgaXMgb2ZmIHRoZSBmcm9udCBwYWdlIGFuZCBoYXMgbm90IGJlZW4gYnVtcGVkIGluIG92ZXIgYSBtb250aC48L2xpPjxsaT48aW5wdXQgdHlwZT0iY2hlY2tib3giIGlkPSJxNyIgY2hlY2tlZD0iY2hlY2tlZCI+IGkgaGF2ZSB2aXNpdGVkIC9iLywgL2cvLCAvbG91bmdlLywgb3IgL3ByLyBpbiB0aGUgbGFzdCBtb250aC48L2xpPjwvb2w+PHA+PGlucHV0IHR5cGU9InN1Ym1pdCIgdmFsdWU9InNob3VsZCBpIHVzZSBzYWdlPyI+PC9wPjwvZm9ybT48L2JvZHk+PC9odG1sPgo=

Name: Anonymous 2009-07-02 8:20

>>32-33
lol shiichan

i don't know of any other textboard script that has bugs that make posts show up in the wrong thread.

Name: Anonymous 2009-07-02 8:33

>>35
lol. If this crap is still going on I'll just ask Mr VacBob to go fix it.

Name: Anonymous 2009-07-02 8:53

>>36
i'm sure MrVacBob loves tracking down heisenbugs in poorly-written php code.

Name: Anonymous 2009-07-02 8:57

>>37
Why wouldn't he? I though he lived and breathed for that kind of stuff. I couldn't fathom how much of a pain in the ass it must be to have this site's nose above water to keep it the whole thing from drowning.

Name: Anonymous 2009-07-02 10:30

>>31
>support
>ignore small implementation defined things such as the size of an integer in the standard
I almost HBT, but no cigar.

Name: Anonymous 2010-12-06 9:53

Back to /b/, ``GNAA Faggot''

Don't change these.
Name: Email:
Entire Thread Thread List