It is necessary to display the first word in the line. I tried to assign the string characters to the variable char and display them up to a space. Nothing happened.

int c = 0; while (char b = fam.get(i).charAt(c); b != " "; c++) { System.out.println(b); } 

Please tell me how it will be right?

  • 1. String input = "First second third"; String [] array = input.split (""); System.out.println (array [0]); 2. String data = "First second third"; StringTokenizer tokens = new StringTokenizer (data, ""); System.out.println (tokens.nextElement ()); - lightcyber

1 answer 1

formatted your code:

 int c = 0; while ( char b = fam.get(i).charAt(c); b != " "; c++) { System.out.println(b); } 

Oh dear, this is the porridge in your head!

I do not even know what to advise and where to send to read.

  1. for starters, I think it's worth understanding the difference between for () {}, while () {} and do {} while () loops
  2. then I think it’s worth finding out

     System.out.print() System.out.printf() System.out.println() 
  • Line b! = ""; does not pass. And the code proposed above has passed. String input = "First second third"; String [] array = input.split (""); System.out.println (array [0]); Thank you very much! - gloryz
  • Of course it does not work! @gloryz are you kidding? I copied and formatted your code from your question, except that I correctly formatted it in order to show that heresy that you wrote! immediately stop copying and grab your studies, otherwise you will never become a programmer (and even a coder) - ProkletyiPirat