public class Number {
public static void main(String[] args) {
int numberEntered;
int firstDigit;
int secondDigit;
int thirdDigit;
int fourthDigit;
int fifthDigit;
getNumberFromUser getNumberFromUserObject = new getNumberFromUser();
getNumberFromUserObject.input();
calculateDigits calculateDigitsObject = new calculateDigits();
calculateDigitsObject.digits();
displayDigits displayDigitsObject = new displayDigits();
displayDigitsObject.display();
}
}
import java.util.Scanner;
public class getNumberFromUser {
public void input () {
Scanner input = new Scanner (System.in);
System.out.print("Enter a five digit number: ");
int numberEntered = input.nextInt();
}
}
public class calculateDigits {
public void digits() {
int numberEntered = 0;
int firstDigit = (numberEntered/10000);
int secondDigit = (numberEntered/1000%10);
int thirdDigit = (numberEntered/100%10);
int fourthDigit = (numberEntered/10%10);
int fifthDigit = (numberEntered/1%10);
}
}
public class displayDigits {
public void display () {
int firstDigit = 0;
int secondDigit = 0;
int thirdDigit = 0;
int fourthDigit = 0;
int fifthDigit = 0;
System.out.println(firstDigit);
System.out.println(secondDigit);
System.out.println(thirdDigit);
System.out.println(fourthDigit);
System.out.println(fifthDigit);
}
}
The first two classes of this java project are working fine.
I need to create a program that will allow me to enter a five digit number and split them into 5 seperate digits.
The classes calculateDigits and displayDigits are the ones that I need help with.
I have done the math already in a previous program , I just don't know how to implement it into a java project with multiple classes.

New Topic/Question
Reply



MultiQuote




|