-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForLoopErrors.java
More file actions
84 lines (68 loc) · 2.3 KB
/
Copy pathForLoopErrors.java
File metadata and controls
84 lines (68 loc) · 2.3 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package unitone.test;
// The "ForLoopErrors" class.
import java.io.*;
public class ForLoopErrors
{
public static void main (String[] args) throws IOException
{
DataInputStream input = new DataInputStream (System.in);
//////////////////////////////////////////////////////////////////////
// Display Help! 20 times
for (int i = 1 ; i <= 20 ; i++)
{
System.out.println ("Help!");
}
System.out.println ("");
//////////////////////////////////////////////////////////////////////
// Display the numbers 1 - 15 all on one line
for (int i = 1 ; i <= 15 ; i++)
{
System.out.print("x");
}
System.out.println ("");
//////////////////////////////////////////////////////////////////////
// Display the numbers 1-5, their squares, and their cubes in a table
System.out.println ("Number/tSquare/tCube");
for (int x = 1 ; x <= 5 ; x++)
{
System.out.println (x + "\t" + x*x + "\t" + x*x*x);
}
System.out.println ("");
//////////////////////////////////////////////////////////////////////
// Ask the user to enter 5 marks which may include decimals
// Display the total and average of the marks
double mark=0, total = 0;
for (int x = 1 ; x <= 5 ; x++)
{
System.out.println ("Enter mark # " + x + " ");
mark = Integer.parseInt (input.readLine());
total = mark + total;
}
System.out.println ("The total of the marks is " + total);
System.out.println ("The average of the marks is " + total / 10);
System.out.println ("");
////////////////////////////////////////////////////////////////////////
// Count down from 25 to 1
for (int x = 25 ; x >= 1 ; x--)
{
System.out.println (x);
}
System.out.println ("");
//////////////////////////////////////////////////////////////////////
// Roll a "die" 50 times and display each;
// Count and display the number of times the '3' is rolled
double dice, count = 0;
for (int i = 1 ; i <=50 ; i++)
{
dice = (int) (Math.random () * 6 + 1);
System.out.println(dice);
if (dice == 3)
{
count++;
}
}
System.out.println ("The number 3 was rolled " + count + " times");
System.out.println ("");
//////////////////////////////////////////////////////////////////////
} // main method
} // ForLoopExercises class