-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatPair.java
More file actions
63 lines (47 loc) · 1.33 KB
/
FloatPair.java
File metadata and controls
63 lines (47 loc) · 1.33 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
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Scanner;
/**
* A class that can format string given a certain pattern.
*
*/
public class FormatStrings {
Scanner in = new Scanner(System.in);
String input1, results, pattern1;
int counter=0;
int i=0;
boolean redo = false;
/**
* Formats any given string to the an X and - pattern.
* @return the formated string
*
*/
public void formatString(){
System.out.println("Enter input to format");
String input = in.nextLine();
input1 = input;
int sizeinput = input1.length();
do {
System.out.println("Enter a patter you want containing only \"x\" and \"-\" ");
String pattern = in.nextLine();
char[] formatString = pattern.toCharArray();
int sizeformat = pattern.length();
for (i = 0; i < sizeformat; i++)
if (formatString[i] == 'x' && counter < sizeinput)
formatString[i] = input1.charAt(counter++);
else if (i>= sizeinput)
formatString[i] =' ';
System.out.println(formatString);
System.out.println("Would you like a new pattern for the same String? Enter 'yes'. If not enter anything to go back to String Menu ");
i =0;
counter=0;
String repeat = in.nextLine();
if (repeat.equals("yes"))
{ redo = true; }
else
{
redo = false; }
}
while (redo == true);
}
}