-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayScannerTime.java
More file actions
39 lines (28 loc) · 910 Bytes
/
ArrayScannerTime.java
File metadata and controls
39 lines (28 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package examples;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class ArrayScannerTime {
public static void main(String[] args) {
int i = 0, lengthFileName = 0, maxLength = 0, longFile = 0;
String fileName[] = new String[10];
String date[] = new String[10];
Scanner sc = new Scanner(System.in);
SimpleDateFormat fmt = new SimpleDateFormat("hh:mm:ss");
do {
System.out.print("\nEnter File Name: - ");
fileName[i] = sc.next();
date[i++] = fmt.format(new Date());
lengthFileName++;
System.out.print("\nFile Added.Do you want enter another file name?y/n...");
} while (sc.next().equals("y"));
sc.close();
for (i = 0; i < lengthFileName; i++) {
if (fileName[i].length() > maxLength) {
maxLength = fileName[i].length();
longFile = i;
}
}
System.out.println("Longest FileName is " + fileName[longFile]);
}
}