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

Why?

Name: Anonymous 2009-11-11 1:47

yes, i know it is long.
When I run it it makes e = 319 instead of just 4.
I have looked at it for about and hour and need some fresh eyes.
I'm working on creating "addresses" for a larger project and I can't seem to figure out why it is running the way it is.

public class whatever
{
    public static void main(String[] args)
    {
        new whatever();
    }
   
    public whatever()
    {
        String str = "eat";
        String str2 = "ate";
       
        for(int i=0;i<str.length();i++)
        {
           
            System.out.println(addressing(str,i));
        }
    }
   
    private int addressing(String word, int x)
    {
        int address = 0;
        word=word.toLowerCase();
        System.out.println(word.charAt(x));
       
        switch(word.charAt(x))
        {
            case 'a':
                address = address+0;
               
            case 'b':
                address = address+1;
               
            case 'c':
                address = address+2;
               
            case 'd':
                address = address+3;
               
            case 'e':
                address = address+4;
           
            case 'f':
                address = address+5;
           
            case 'g':
                address = address+6;
           
            case 'h':
                address = address+7;
           
            case 'i':
                address = address+8;
           
            case 'j':
                address = address+9;
           
            case 'k':
                address = address+10;
           
            case 'l':
                address = address+11;
           
            case 'm':
                address = address+12;
           
            case 'n':
                address = address+13;
           
            case 'o':
                address = address+14;
           
            case 'p':
                address = address+15;
           
            case 'q':
                address = address+16;
           
            case 'r':
                address = address+17;
           
            case 's':
                address = address+18;
           
            case 't':
                address = address+19;
           
            case 'u':
                address = address+20;
           
            case 'v':
                address = address+21;
           
            case 'w':
                address = address+22;
           
            case 'x':
                address = address+23;
           
            case 'y':
                address = address+24;
           
            case 'z':
                address = address+25;
            //default:
                //address = address;
        }
       
        return address;
    }
}

Any help would be appreciated.

Name: Anonymous 2009-11-11 2:12

My other car is a cdr.

Name: Anonymous 2009-11-11 2:57

switch(word.charAt(x))
        {
            case 'a':
                address = address+0;
...

What a horrible solution!

Name: Anonymous 2009-11-11 3:18

>>3
It's Java. It's an ENTERPRISE SOLUTION!

Name: Anonymous 2009-11-11 3:30

public class whatever
{ public static void main(String[] args)
  { new whatever(); }

  public whatever()
  { String str = "eat";
    for(int i = 0;
        i < str.length();
        System.out.println(addressing(str, i++))); }

  private int addressing(String word, int x)
  { char character = word.toLowerCase().charAt(x);
    System.out.println(character);
    return character > 'a' && character <= 'z' ? character - 'a' : 0; }}

Name: Anonymous 2009-11-11 3:42

>>5
oh gawd looking at code from people who think they know how to code never gets old.

Name: Anonymous 2009-11-11 3:50


s=s.toLowerCase();for(int i=0;i<s.length;i++)System.out.println(Character.isLetter(s.charAt(i))?s.charAt(i)-'a':0);

Name: Anonymous 2009-11-11 3:54

>>5
Simply awful. Even worse than >>1. My eyes, they bleed.

Name: Anonymous 2009-11-11 4:01

This would be much more elegant if done with a tail-recursive lambda map closure

Name: Anonymous 2009-11-11 4:39

>>8
im hard now

Name: Anonymous 2009-11-11 5:00

>>10
im soft now

Name: Anonymous 2009-11-11 8:22

You could, you know, automate that with a macro

Name: Anonymous 2009-11-11 9:31

>>12
AUTOMATE MY ANUS

oh lawdy i never tire of HMA derivatives

Name: Anonymous 2009-11-11 9:36

Yes yes, I know it isn't pretty. I'm just trying to learn. Its a challenge from my professor and it is about 6 classes above me. This is only a part of a much larger piece of code.

Name: Anonymous 2009-11-11 10:36

Protip: BREAK MY ANUS

Name: Anonymous 2009-11-11 11:34

>>1
You should take a break and come back to it later.

(Actually charAt(x) -'a' is waaaaay better.)

Name: Anonymous 2009-11-11 11:46

2 koreans died laughing at your code, >>1-san. And koreans can't even laugh.

Name: Anonymous 2009-11-11 11:49

>>17
I died laughing at you. And I can't even die.

Name: Anonymous 2009-11-11 13:18

>>18
Archer?

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