I gave up asking my teacher and classmates because they refuse to give me an exact answer, and my Google searches have left me dry since yesterday, and I just can't figure this out.
I need to have the user input a 5 digit number like "12345" or "11111".
I then need to print out just the "1" and on a separate line the "5". The problem is, I can only get "12345" to print, and not just the "1" let alone the "5".
Then I need to add "1" and "5" together on a separate line.
Steps one and two are done, and the code is below, but-
*The third step, I am stuck on is: "Create five variables digit1-digit5, assign them the individual digits of the number entered. hint:use integer division and modulus operator % to isolate the numbers.
import java.util.Scanner;
public class Number
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.printf("Enter a 5 Digit Number: ");
int Number = input.nextInt();
}
}
Here are the exact instructions from the paper:
-Create a file called Number.java. It includes one single method: main. Include a comment with your name and assignment number on the top of the line.
Steps 1-4:
1) Read in a 5 digit number from the user (one single number --do not read in 5 digits)
2)Create a variable called number to store the input entered by the user. No need for input validation. In this assignment you can assume that the user enters a number in the right range.
3)Create five variables digit1-digit5, assign them the individual digits of the number entered. hint:use integer division and modulus operator % to isolate the numbers
4)Print the following info including a descriptive labels as descibed by the output below.
-the first digit
-the last digit
-the sum of the first and last digit*Pass the appropraite expression as an arguement to the printf statment, don't create a variable that stores the sum**
-The whole 5-digit number but seperate the individual digits with 2 spaces(blanks)