forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtraWork.java
More file actions
59 lines (50 loc) · 1.77 KB
/
ExtraWork.java
File metadata and controls
59 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//Denisolt Shakhbulatov
import java.util.Scanner;
class ExtraWork
{
public static void main(String args[])
{
String letter;
do
{
int length = 0;
int reverse = 0;
System.out.print("Enter the number to get a reverse of it: ");
Scanner keyboard = new Scanner(System.in);
int inputVal = keyboard.nextInt();
int inputValforRev = inputVal;
reverse = reverseNum(inputValforRev, reverse);
System.out.println("Reverse of entered number is " + reverse);
length = numberofdigits(inputVal, length);
System.out.println("The number of digits are: " + length);
System.out.print("Enter the index of input: ");
int indexNum = keyboard.nextInt();
indexofinput(inputVal, indexNum);
System.out.println();
keyboard.nextLine();
System.out.println("Do you want to run the program again (Y/N)?: ");
letter = keyboard.nextLine();
}
while (letter.equalsIgnoreCase("y"));
}
public static int reverseNum(int inputValforRev, int reverse)
{
while( inputValforRev != 0 )
{
reverse = reverse * 10;
reverse = reverse + inputValforRev%10;
inputValforRev = inputValforRev/10;
}
return reverse;
}
public static int numberofdigits(int inputVal, int length)
{
length = ((int)Math.log10(inputVal))+1;
return length;
}
public static void indexofinput(int inputVal, int indexNum)
{
String s = Integer.toString(inputVal);
System.out.print("the index of " + indexNum + " is " + s.substring(indexNum,indexNum+1));
}
}