java - I cannot get the program to repeat output in an ordered manner -


i want design program scales strings. if string d = "abc\ndef\nghi",horizontal scalling=2,vertical scalling=2, scaleobj.scale(d,2,2)/defined below/ should output "aabbcc\naabbcc\nddeeff\nddeeff\ngghhii\ngghhii".

//output  aabbcc aabbcc ddeeff ddeeff gghhii gghhii 

ive have problem ive defined below:

//mainsix.java  public class mainsix{     public static void main(string[] args){         scale scaleobj = new scale();         system.out.println(scaleobj.scale("abc\ndef",2,3));     }  }  class scale {      public static string scale(string strng, int k, int v) {          //horizontal scalling -k         string s=strng.replaceall(".", repeat("$0",k));          //verical scalling         string y = repeat(s,v);          return y;      }     public static string repeat(string str, int times){         return new string(new char[times]).replace("\0", str);     } } 

when compile output

aabbcc ddeeffaabbcc ddeeffaabbcc ddeeff  //aabbcc\nddeeffaabbcc\n\nddeeffaabbcc\nddeeff 

how can output

aabbcc aabbcc aabbcc ddeeff ddeeff ddeeff  //aabbcc\naabbcc\n\naabbcc\nddeeffddeeff\nddeeff 

please modify existing code

if want abc\ndef equal aabbcc\nddeeff if scale set 2.

you split string token(chars), replace each char self times scale factor.

a replaced aa, b => bb, c => cc, etc

in example below create new string output, instead of replacing values in input (its preference).

int scale = 2; string s = "abc", ss = ""; (char c : s.tochararray()) {    (int = 0; < scale; i++) {     ss += c;   } } system.out.println(ss); //ss = aabbcc 

edit1:

int scale = 2, rpt = 3; string s = "abc\ndef", ss = ""; (string t : s.split("\n")) { //word loop   (int j = 0; j < rpt; j++) { //repeat loop     (char c : t.tochararray()) { //char loop       (int = 0; < scale; i++) { //scale loop         ss += c;       }     }     ss += "\n";   } } system.out.println(ss);  /* aabbcc aabbcc aabbcc ddeeff ddeeff ddeeff */ 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -