עבור לתוכן

JAVA - הסבר על פקודות

Featured Replies

פורסם

תראו את זה :
[code]
import java.io.File;
import java.util.Scanner;

public class count {

public static void main(String[] args) throws Exception {
Scanner x = new Scanner(new File("test.txt"));
int words = 0;

while(x.hasNext("\\S+")) {

String word = x.next("\\S+");
words++;
}
System.out.println(words);
}
}

התכנית קוראת קובץ טקסט ומדפיסה כמה מילים יש בתוך הקובץ.

יש לי שתי שאלות על הקוד :

1. מה בעצם הפקודה הזו עושה ?

x.hasNext("\\S+")

2. מה הפקודה הזו עושה ?

  String word = x.next("\\S+");

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים