Basics Flashcards

(5 cards)

1
Q

Read Text File

A

can use BufferedReader, FileReader, or Scanner class

File file = new File("C:\\file_path\\test.txt"); 
Scanner sc = new Scanner(file); 

while (sc.hasNextLine())
System.out.println(sc.nextLine());

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Read input from console

A

can use Scanner class (java.util)

Scanner sc = new Scanner(System.in);
String username = scanner.nextLine();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

length vs length()

A

.length is a property of arrays

.length() is a method call for strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write to File

A

Can use PrintWriter class (java.io)

File file = new File("C:/path/file.txt");
PrintWriter pw = new PrintWriter(file);
pw.println("hello")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Binary Search

A

searches a sorted array by repeatedly dividing the search interval in half

How well did you know this?
1
Not at all
2
3
4
5
Perfectly