Last active
October 19, 2021 15:13
-
-
Save maf946/901e75c257b11cd3e0b0cd059bc4f647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package unit4ps21fa; | |
/** | |
* | |
* @author YOUR_NAME_HERE | |
*/ | |
public class Unit4PS21FA { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
/* | |
1. Write a Java program to output the digits 0-9 to the command line, | |
each on a separate line. Use a while loop to control iterations. (1 point) | |
2. Write a Java program to read a string (a password) from the user at the command line | |
and then check that the password conforms to the corporate password policy. | |
The policy is: | |
1) the password must be at least 8 characters | |
2) the password must contain at least one upper case letter | |
3) the password must contain at least one digit. | |
Use a while loop to step through the string. | |
Output “Password OK” if the password conforms, otherwise | |
output “Password does not conform to the policy.” (2 points) | |
3. Write a Java program to generate 6 random lottery numbers. | |
Your program should generate 6 numbers between 1 and 60. | |
Use a for loop to control the 6 iterations. | |
Output the numbers to the command line on a single line e.g.: 6 14 51 35 22 43. (2 points) | |
4. Write a Java program to accept positive integers from the user at the command line. | |
The user can enter as many integers as they like. Use -1 as a sentinel. | |
Keep track of the highest number (the max) they enter. | |
When done output: "The max was X" where X is this highest integer. (2 points) | |
5. Write a Java program that uses nested for loops to print a multiplication table as shown below. | |
Make sure to include the table headings and separators as shown. | |
The values in the body of the table should be computed using the values in the heading | |
e.g. row 1 column 3 is 1 times 3. (3 points) | |
* | 1 2 3 4 5 6 7 8 9 | |
------------------------------- | |
1 | 1 2 3 4 5 6 7 8 9 | |
2 | 2 4 6 8 10 12 14 16 18 | |
3 | 3 6 9 12 15 18 21 24 27 | |
4 | 4 8 12 16 20 24 28 32 36 | |
5 | 5 10 15 20 25 30 35 40 45 | |
6 | 6 12 18 24 30 36 42 48 54 | |
7 | 7 14 21 28 35 42 49 56 63 | |
8 | 8 16 24 32 40 48 56 64 72 | |
9 | 9 18 27 36 45 54 63 72 81 | |
*/ | |
// Write your answer to #1 below here | |
// Write your answer to #2 below here | |
// Write your answer to #3 below here | |
// Write your answer to #4 below here | |
// Write your answer to #5 below here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment