In: Computer Science
How do you post only up to 10 shingle pairs per line in java?
Example output:
'Ho' 'w ' 'ar' 'e ' 'yo' 'u ' 'do' in' ' g' ' t'
'od' 'ay' '? '
I hope the following code demonstrates what you are looking
for....
To indent code in eclipse , select code by pressing ctrl+a and then
indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
public class Print10 {
public static void main(String[] args) {
String s = "How are you doing today ?";
int count = 1;
int max_per_line = 10;
String substr;
for(int i = 0; i < s.length(); i+= 2)
{
if(i+1 < s.length())
substr = s.substring(i, i+2);
else
substr = s.substring(i, i + 1);
System.out.printf("'%s' ", substr);
if(count == max_per_line)
{
System.out.println();
count = 1;
}
else
count++;
}
}
}
output
-----
'Ho' 'w ' 'ar' 'e ' 'yo' 'u ' 'do' 'in' 'g ' 'to'
'da' 'y ' '?'