-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivNEqualParts.java
More file actions
47 lines (44 loc) · 1.65 KB
/
DivNEqualParts.java
File metadata and controls
47 lines (44 loc) · 1.65 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
import java.util.Scanner;
class DevString {
void devStringUsingSub(String sText, int iParts) {
if(sText.length() % iParts == 0){
iParts = sText.length() / iParts;
for(int i = 0; i < sText.length(); i+=iParts){
String sSub = sText.substring(i, i + iParts);
System.out.print ("|" + sSub + "| ");
}
}
else
System.out.println("Divding the string (" + sText + ") in " + iParts + " equal parts is not possible.");
}
void devString(String sText, int iParts) {
if(sText.length() % iParts == 0) {
iParts = sText.length() / iParts;
for(int i = 0; i < sText.length(); i+=iParts){
int iCheck = 0;
String sSub = "";
while(iCheck < iParts){
sSub = sSub + sText.charAt(i+iCheck);
iCheck += 1;
}
System.out.print ("|" + sSub + "| ");
}
}
else
System.out.println("Divding the string (" + sText + ") in " + iParts + " equal parts is not possible.");
}
}
public class DivNEqualParts {
public static void main(String[] args) {
String sText;
int iParts;
DevString dev = new DevString();
Scanner input = new Scanner(System.in);
System.out.print("Enter the String: ");
sText = input.nextLine();
System.out.print("How many parts do you want to split the string: ");
iParts = input.nextInt();
dev.devString(sText, iParts);
// dev.devStringUsingSub(sText, iParts);
}
}