• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string code problem

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have string s = "r88i66t76s76h43";

i want output first three character then leave two character then again three
like
r88
6t7
76h

i had tried tht code but its nt give proper output(my taken string is differ from upper string..)


public class AlterStringDemo {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "r98i345e45s77h9";
char ch[]= s.toCharArray();
for(int i=0;i<ch.length;i++){
for(int j=1;j<4;j++){


System.out.print(ch[i]);
continue;
}for(int k=1;k<3;k++){
System.out.println("");
}

}

}

}
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved from JavaFX. ritesh srivastav, please do learn to UseCodeTags <- link

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ritesh srivastav wrote:i have string s = "r88i66t76s76h43";

i want output first three character then leave two character then again three
like
r88
6t7
76h

i had tried tht code but its nt give proper output(my taken string is differ from upper string..)


public class AlterStringDemo {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "r98i345e45s77h9";
char ch[]= s.toCharArray();
for(int i=0;i<ch.length;i++){
for(int j=1;j<4;j++){


System.out.print(ch[i]);
continue;
}for(int k=1;k<3;k++){
System.out.println("");
}

}

}

}



My normal response would be to print out what the loop values -- and you should easily see what is going on. However, since you already did that, perhaps you should print out the loop indexes as well.

Another option is to play computer, and follow your program using paper and a pencil -- it will quickly become clear why the program is outputting the results you see.

Henry
 
I didn't say it. I'm just telling you what this tiny ad said.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic