10-22-2013, 12:09 PM
I have been following these tutorials but I can't seem to find the problem. I changed some names just so that it makes me think a little more.
Here is what i have:
Here is what i have:
Code:
public class digitextractor {
int number = 0;
String snumber = "";
public digitextractor(int numberSequence) {
int number = numberSequence;
}
public digitextractor(String numberSequence){
snumber = numberSequence;
}
public void returnorder(){
int integer1 = 0;
int integer2 = 0;
int integer3 = 0;
int integer4 = 0;
int integer5 = 0;
integer1 = (number % 10);
integer2 = (number % 100) / 10;
integer3 = (number % 1000) / 100;
integer4 = (number % 10000) / 1000;
integer5 = (number % 100000) / 10000;
System.out.println(integer1 + "\n" + integer2 + "\n" +
integer3 + "\n" + integer4 + "\n" + integer5);
}
public void returnorderThroughString(){
char part1;
char part2;
char part3;
char part4;
char part5;
part1 = snumber.charAt(4);
part2 = snumber.charAt(3);
part3 = snumber.charAt(2);
part4 = snumber.charAt(1);
part5 = snumber.charAt(0);
System.out.println(part1 + "\n" + part2 + "\n" + part3 + "\n" + part4 + "\n" + part5);
}
}
Code:
import java.util.Scanner;
public class digitfinished {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// process starts
System.out.println("Welcome to this thing." + "\n" + "Enter your number");
String in = input.nextLine();
digitextractor product = new digitextractor(Integer.parseInt(in));
product.returnorderThroughString();
System.out.println("Using Strings");
digitextractor output = new digitextractor(in);
output.returnorderThroughString();
}
}