-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringManipulator.java
More file actions
64 lines (56 loc) · 2.13 KB
/
StringManipulator.java
File metadata and controls
64 lines (56 loc) · 2.13 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
60
61
62
63
64
/*
* Name: Adam Mason
* Date: 1/23/2019
* Project Description:
*/
import java.util.Scanner;
import java.util.Random;
public class StringManipulator
{
public static void main( String args[] )
{
Scanner scan = new Scanner(System.in);
Random rand = new Random();
int subString1, subString2, uppercaseIndex = -1, inputLength;
char randChar;
String input = " ";
boolean uppercaseContained = false;
while( input.length() < 8 || input.length() > 15 )
{
System.out.println("Enter a string that is longer than 8 but less than 15: ");
input = scan.nextLine();
}
inputLength = input.length();
randChar = input.charAt( rand.nextInt( inputLength ));
subString1 = rand.nextInt( inputLength - 1);
subString2 = rand.nextInt( inputLength - subString1 ) + subString1;
System.out.println( "String length: " + inputLength );
System.out.println( "Random Character: " + randChar );
System.out.println( "Substring: " + input.substring(subString1,subString2 + 1) );
System.out.println( "Random Starting Character: " + input.substring(rand.nextInt(inputLength - 1)) );
System.out.println( "Uppercase: " + input.toUpperCase() + "\nLowercase: " + input.toLowerCase() );
for( int i = 0; i < input.length(); i++ )
{
if( input.charAt(i) >= 65 && input.charAt(i) <= 90 )
{
uppercaseContained = true;
int upperCaseLocation = i;
if( uppercaseIndex < 0 )
{
uppercaseIndex = input.charAt(i);
}
}
}
if( uppercaseContained == true && uppercaseIndex > 0 )
{
System.out.println( "Uppercase Contained" );
System.out.println( "Uppercase at index: " + (char)(uppercaseIndex) );
}
System.out.print("Reversed: ");
for( int j = inputLength - 1; j > -1; j-- )
{
System.out.print( input.charAt(j) );
}
}
}
//end-of-file