AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Java Program for Stretch Factor

write a Java Program that accepts Stringa and an integer stretch factor P as parameters and that replaces each element with k copies of that element. For example, if a variable called list stores the elements [hi, how, are, you?], then the call of stretch(list, 3); it will store [hi, hi, hi, how,how,how,are,are,are, you?, you?, you?]. If a stretch factor of 0 or less is passed, the list is made empty. In this case, print "EMPTY" You can assume that the input list will never be empty. Sample input: 3 hi how are you? sample output: hi hi hi how how how are are are you? you? You?

corejava x 336
programming x 153
Posted On : 2016-12-22 10:41:53.0
profile Navin Kumar - anyforum.in Navin Kumar
1000
up-rate
4
down-rate

Answers


import java.util.Scanner;

public class StretchFactor {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String[] inputs=input.nextLine().split(" ");
int factor=Integer.parseInt(inputs[0]);
StringBuffer sb=new StringBuffer();
for(int k=1;k<inputs.length;k++){
for(int i=0;i<factor;i++){
sb.append(inputs[k]+" ");
}
}
System.out.println(sb.toString().trim());
}
}

Posted On : 2016-12-22 23:32:54
Satisfied : 2 Yes  1 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523185319307
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in