Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Date:2014.09.30
- * @author LinChuWen
- * NCHU EE,course number:2335
- * course name:Object Oriented Language
- *
- * Problem:Write a program that reads in an integer
- * and breaks it into a sequence of individual digits.
- * For example, the input 16384 is displayed as 1 6 3 8 4
- * You may assume that the input is not negative.
- */
- import java.util.*;
- public class HW1 {
- public static void main(String[] args) {
- int cnt;
- int number;
- int[] array = new int[10];
- Scanner input = new Scanner(System.in);
- try{
- System.out.print("Please enter an integer: ");
- number = input.nextInt();
- int length = String.valueOf(number).length();
- for(cnt=0;cnt<length;cnt++){
- array[cnt]=number%10;
- number/=10;
- } //for end
- for(cnt=length-1;cnt>=0;cnt--){
- System.out.print(array[cnt]+" ");
- } //for end
- } //try end
- finally{
- input.close();
- } //finally end
- } //main end
- } //HW1 end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement