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
import java.util.Scanner; | |
public class Hangman | |
{ | |
public static void main( String[] args ) | |
{ | |
String[] word_list = { "ruby", "python", "java", "tootsie", "chairlift", "kittens" }; | |
String rand_word; | |
char[] hidden_word; |
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
/* | |
Count occurrence of numbers) Write a program that reads the integers between 1 | |
and 100 and counts the occurrences of each. Assume the input ends with 0. Here | |
is a sample run of the program: | |
Programming Exercises 277 | |
Enter the integers between 1 and 100: 2 5 6 5 4 3 23 43 2 0 | |
2 occurs 2 times | |
3 occurs 1 time | |
4 occurs 1 time | |
5 occurs 2 times |
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
''' | |
2. Prompt the user to guess your favorite color. Using a while loop, if the user didn't guess your favorite color [pick one for this activity] then tell them they are incorrect, then ask them again. Whenever they guess the color correctly, output that they are correct and how many guesses it took them. | |
Create a variable and assign it the value of 1 | |
Prompt the user to guess your favorite color | |
While their guess is not equal to your favorite color | |
Tell them they are incorrect | |
Prompt them to guess again | |
Add one to the variable above | |
Output to the user, they were correct and how many attempts it took using the variable |
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
/* | |
(Count single digits) Write a program that generates 100 random integers between | |
0 and 9 and displays the count for each number. (Hint: Use an array of ten integers, | |
say counts, to store the counts for the number of 0s, 1s, . . . , 9s.) | |
*/ | |
public class CountSingleDigits { | |
public static void main(String[] args) { | |
int[] ________ = new int[___]; |
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
''' | |
3. Ask the user how many numbers for which they want to calculate the sum. Using a for loop, prompt the user to enter that many numbers, one-by-one, keeping track of the sum. At the end, after the user entered all numbers, output the sum. | |
Create a variable and assign it the value of 0 | |
Prompt the user for how many numbers they have | |
With a for loop, set it to repeat enough times to get all their values | |
Prompt the user for a number | |
Add that number to the variable that started as 0 | |
Output to the user, the sum of all values |
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
import java.util.Scanner; | |
public class FindFutureDates_03_05 { | |
public static void main(String[] args) { | |
// Prompt the user to enter an integer for today | |
System.out.print("Enter today’s day: "); | |
_________________________________________ | |
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
public class Lottery_03_15 { | |
public static void main(String[] args) { | |
// Generate a lottery using Math.random here for 3 digits using a variable called lottery. | |
// Prompt the user to enter a guess by asking them to enter three digits. Variable must be called guess and be intialized as an it. | |
java.util.Scanner input = new java.util.Scanner(System.in); | |
// Get digits | |
int l1 = lottery / 100; |
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
public class DisplayLeapYear_Exercise05_27 { | |
public static void main(String[] args) { | |
int count = __; | |
for (int year = ___; year <= ______; year++) { | |
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) | |
System.out.print((++count % 10 == 0)? year + "\n": year + " "); | |
} | |
System.out.println("The number of leap year is " + count); | |
} |
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
''' | |
Create a new program in Repl.it called "Lists." Your goal for this program is to create sections of code that will perform different | |
outputs with the list called, names which contains the following values - Peter, Bruce, Steve, Tony, Natasha, Clint, Wanda, Hope, | |
Danny, Carol and the list called numbers which contains the following values - 100, 50, 10, 1, 2, 7, 11, 17, 53, -8, -4, -9, -72, -64, | |
-80. At the beginning of your program, add in any comments and create the two lists. Then create the following: | |
A loop that will output every other name in the names list. | |
A loop that will output only the positive numbers in the numbers list. | |
A loop that will output the sum of all the values in the numbers list. | |
A loop that will output only the numbers that are odd. |
NewerOlder