string - Creating a Infinite While Loop Errors in Java -
I try to apply my word frequency to java < infinity while loop I'm Code The goal of this code was to create a program through the analysis of the main method JAVA was a piece text that was entered from a user.
They do this by placing the text in a scanner, which is then analyzed by the program.
Import java.util.Scanner;
public class wordfac {public static zero main (string [] args) {scanner input = new scanner (System.in); System.out.println ("Enter Text:"); String s; S = input.nextLine (); System.out.println ("" + s); String [] string = s.split (""); Int [] calculation = new int [6]; (Str.length () & lt; count.length) for calculation [str.length ()] + = 1; (Int i = 1; i & lt; count.length; i ++) System.out.println (i + "letter word:" + count [i]) for; Input.Close ();}}
The user can re-enter a part of the text to re-analyze it again and I have this piece of code, It is infinite, but when I try to merge two then I keep getting errors.
import java.util.Scanner; Public Segment While Leap {Public Stable Zero Main (String AZ []) {Scanner Scan = New Scanner (System.in); String line = ""; While ((line = scan.NXTin ())! = Null {string token [] = line split (""); For (int i = 0; i & amp; lt; tokens.length; i ++) {System.out.println (token [i]); }}}
I'm not the best in Java and I do not expect to give me a code, but if someone can point out what I should do or just correct me Tell the direction that it will be highly appreciated.
You have not clarified how exactly you merge code and what kind of errors are coming up But your while
is not good at the loop, you have to wait for user input inside the "infinite" loop.
while (true) {// end loop scanner = new scanner (System.in); While (for.hasNextLine ()) // Input for System.out.println (in.nextLine ()); // Process Input}
Every time the user presses 'Input', you do the process on your input. Of course you can do anything you want in.nextLine () 'or
in.next () `and the end of the loop of your time may be because I suspect you're 100% infinite Loop, but the structure must be the same. Hope this will be helpful.
Edit: Try the following code:
while (true) {scanner input = new scanner (System.in); System.out.println ("Enter Text:"); String s; S = input.nextLine (); System.out.println ("" + s); String [] string = s.split (""); Int [] calculation = new int [6]; (Str.length () & lt; count.length) for calculation [str.length ()] + = 1; (Int i = 1; i & lt; count.length; i ++) System.out.println (i + "letter word:" + count [i]) for; }
However, there is not much chance that you need a true infinite loop, so put the status of some restrictions in the loop of your time.
Comments
Post a Comment