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

Pages: 1-

HELP WITH JAVA 101

Name: Anonymous 2009-02-04 20:26

How do i make a program kinda like:
It should ask the user to enter the number and compute the answers.


Enter a three-digit positive integer: 765

The hundreds digit is: 7
The tens digit is: 6
The ones digit is: 5

Name: Anonymous 2009-02-04 20:30

umm did you ever think maybe... DIVIDE

Name: Anonymous 2009-02-04 20:31

divide wut?

Name: Anonymous 2009-02-04 20:34

Jesus fucking Christ.

Name: Anonymous 2009-02-04 20:39

CL-USER>(/ 345 Jesus-fucking-Christ)
/: division by Jesus
   [Condition of type SYSTEM::SIMPLE-DIVISION-BY-JESUS]

Name: Anonymous 2009-02-04 20:40

>>1-5
Same person, and we have been trolled exponentially

Name: Anonymous 2009-02-04 20:42

>>5
thks bro

Name: HMA 2009-02-04 21:09

(defn print-digits [n]
  (let [num-str (str n)]
    (println "The hundreds digit is: " (nth num-str 0 "0"))
    (println "The tens digit is: " (nth num-str 1 "0"))
    (println "The ones digit is: " (nth num-str 2 "0"))))

(defn main []
  (println "Enter a three-digit positive integer: ")
  (print-digits (Integer/parseInt (read-line))))

AND THAT, MY FRIENDS, IS THE POWER OF RECURSION

Name: Anonymous 2009-02-04 21:14

how come we have no mods on /prog/ ? seriously?

Name: Anonymous 2009-02-04 21:37

faggot :: (Integral a) => a -> [a] -> [a]
faggot a b
  | a < 10 = a : b
  | otherwise = faggot (quot a 10) ((mod a 10) : b)

Name: Anonymous 2009-02-04 21:38

>>8
i need this in Java

Name: Anonymous 2009-02-04 23:00

>>11
Print >>8
Roast and brew a cup of Java Kajumas Organic Taman Dadar
Place printout in cup of Java

Name: Anonymous 2009-02-04 23:04

>>11
I wrote you an enterprise quality solution.

import java.util.Scanner;
/**
* An object of class Digit represents one digit in a three digit number
*/
public class Digit {
    /**
    * Main method which gets a valid number from the standard stream out outputs a series of lines pertaining to the value of each place digit in said number
    *
    * @param args the command line arguments for this program, they are not used
    */
    private static final int NUMDIGITS = 3;
    private static final String[] digits = {"ones","tens","hundreds","thousands","ten thousands","hundred thousands","millions"};
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String number = "";
        Digit[] digits = new Digit[NUMDIGITS];
        while(true) {
            System.out.print("Enter a "+NUMDIGITS+" digit positive integer: ");
            number = scan.nextLine();
            if(getNumber(number)) {
                break;
            }
            else {
                System.out.println();
                System.out.println("You didn't enter a "+NUMDIGITS+" digit number! try again");
            }
        }
        for(int i=0; i<NUMDIGITS; i++) {
            digits[i] = new Digit(i, Integer.parseInt((new Character(number.charAt(i))).toString()));
        }
        for(Digit digit : digits) {
            System.out.println(digit.toString());
        }
    }
    /**
    * Static method to parse a string entered by the user and determine if it is a valid number and three digits long
    *
    * @param number the string representing the input by the user
    * @param writeNum the Integer in which this method should write the output integer
    * @return true if it is a three digit number, otherwise false
    */
    private static boolean getNumber(String number) {
        boolean returnval = false;
        try {
            Integer.parseInt(number);
            if(number.length()!=NUMDIGITS) {
                throw new NumberFormatException("Number is not "+NUMDIGITS+" digits!");
            }
            returnval = true;
        }
        catch(NumberFormatException e) {
        }
        return returnval;
    }
    private int position;
    private int value;
    private String digitValue;
    /**
    * Constuctor for objects of type Digit
    *
    * @param position the position of this digit in the three digit string it is a child of
    * @param value the single digit value of this digit
    */
    public Digit(int position, int value) {
        this.position = position;
        this.value = value;
        this.digitValue = "The "+digits[NUMDIGITS-position-1]+" digit is: ";
    }
    /**
    * Overridden toString() method to convert this digit to a textual representation of what it represents
    *
    * @return the string representation
    */
    public String toString() {
        return this.digitValue+new Integer(this.value).toString();
    }
}

Name: Anonymous 2009-02-04 23:15

>>13
Actually, it's not that bad. I wouldn't say it's really ENTERPRISE-quality. I've seem much worse by people who were trying.

Name: Anonymous 2009-02-04 23:58

>>13
This actually looks all right.

Name: Anonymous 2009-02-05 9:19

>>13
Where is the factory?

Name: Anonymous 2009-02-05 10:22

>>13
    private static final int NUMDIGITS = 3;
I'm afraid you'll have to put this in a ConstantFactory that loads constants from an XML database on another server.  Also for true, false, and 0.

Name: Anonymous 2009-02-05 14:24

Speaking of true false, languages that implement true as 1 and not -1 are for faggots. The opposite of all zeros is all ones, which is -1.

Name: Anonymous 2009-02-05 14:37

>>18
Screw your signed two's complement integers, negative numbers are for emo faggots. Go cut yourself while I'm here with my happy positive numbers.

Name: Anonymous 2009-02-05 14:54

op here, can you make a simpler version of this?

Name: Anonymous 2009-02-05 15:02

Do your own homework.

Name: Anonymous 2009-02-05 15:44

>>20
Why don't you just drop the class.

Name: Anonymous 2009-02-05 15:57

>>22
WHY DON'T U SUCK MY DICK?

Name: Anonymous 2009-02-05 15:58

>>23
WHY DON'T YOU READ YOUR SICP?

Name: Anonymous 2009-02-05 16:02

>>23
Y DON U HAX MY ANUS?

Name: Anonymous 2009-02-05 16:06

>>25
KINDA LIKE TACTICAL PENETRATION?

Name: Annoymous 2009-02-05 16:45

I believe we should ban tof

Name: Anonymous 2009-02-05 17:50

>>11
It's clojure. Just add a loader class in Java and you're done.

Name: Anonymous 2009-02-25 6:49

The conclusion that it   was a faggoty   cartoon made for   9 year old   She can barely   spell her own.

Name: Anonymous 2010-11-26 18:55

Name: Anonymous 2011-02-03 3:15


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