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

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

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