Intro to Java Project...need help with printing out numbers and the mod (%) operator

Discussion in 'OT Technology' started by Gli, Jan 16, 2008.

  1. Gli

    Gli i can has fast duck?

    Joined:
    Jan 8, 2007
    Messages:
    859
    Likes Received:
    0
    Location:
    San Francisco, CA
    I have to do a project and I'm totally stuck.

    It pops up an input window and say you type in "23"

    It needs to print out:
    3
    2
    0

    Basically hundredths place but in reverse.

    This is what I have so far:
    Code:
    String s = JOptionPane.showInputDialog("Enter an integer");
        int num = Integer.parseInt(s); // turns a String into an int.
            if num = negative
                num = num * -1
                else num = num * 1
                
        int ones = num % 10;
        int tens = (num % 10) - ones;
        
        System.out.println(ones);
        System.out.println(tens);
        
        
        
        }
        
    }
    The "negative" is just a place holder until I find out how to say if a number is negative, times it by -1 to make it positive.

    So far only "ones" is printed out right....I don't know how to get the tens place to print out correctly.

    Halp me? :x:
     
  2. Gli

    Gli i can has fast duck?

    Joined:
    Jan 8, 2007
    Messages:
    859
    Likes Received:
    0
    Location:
    San Francisco, CA
    Fuck it, I figured it out by myself. :( This subforum sucks the cock...amirite?
     
  3. sonicsuby

    sonicsuby New Member

    Joined:
    Mar 15, 2000
    Messages:
    21,338
    Likes Received:
    0
    Location:
    CA
    No it doesn't, noob sauce. There just either aren't a lot of programming people here, not many know JAVA or none of those that do saw your thread.
     
  4. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    And those of us that do, know to read the two FUCKING stickies before posting.
     
  5. wabash9000

    wabash9000 Active Member

    Joined:
    Dec 27, 2006
    Messages:
    14,392
    Likes Received:
    0
    Location:
    Overland Park, KS
    Code:
    String s = JOptionPane.showInputDialog("Enter an integer");
        int num = Integer.parseInt(s); // turns a String into an int.
        if (num < 0)
            num = num * -1
            else num = num * 1
        int temp=0;
        while (num!=0){
            temp=num%10;
            num=num/10;
            System.out.println(temp);
        }
    }
    
    you are hopeless.
     

Share This Page