-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradesInAnArrayAndFile.java
More file actions
45 lines (34 loc) · 960 Bytes
/
Copy pathGradesInAnArrayAndFile.java
File metadata and controls
45 lines (34 loc) · 960 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
40
41
42
43
44
45
import java.util.Random;
import java.util.Scanner;
import java.util.Arrays;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
public class GradesInAnArrayAndFile
{
public static void main( String[] args )
{
try{
int [] myIntArray = new int [ 5 ];
PrintWriter fileout;
fileout = new PrintWriter(new FileWriter("utto.txt"));
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
String user_name = keyboard.next();
String last_name = keyboard.next();
for (int i = 0; i < myIntArray.length; i++)
{
myIntArray[i] = r.nextInt(100);
System.out.println("Grade" + (i + 1) + ":" + myIntArray[i]);
fileout.println("Grade" + (i + 1) + ":" + myIntArray[i]);
}
System.out.println(user_name);
System.out.println(last_name);
fileout.println(user_name);
fileout.println(last_name);
fileout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}