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. |
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
''' | |
1. Prompt the user for a number from 1 to 100. Using a while loop, if they entered an invalid number, tell them the number entered is invalid and then prompt them again for a number from 1 to 100. If they enter a valid number - thank them for their input. | |
Prompt the user for a number from 1 to 100 | |
While that number is less than 1 or that number is more than 100 | |
Output that they entered an invalid number | |
Prompt them again for a number from 1 to 100 | |
Output to the user, thanking them for their input | |
''' |
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
''' | |
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 StringStatsArray{ | |
private final String[] arr; | |
public StringStatsArray(String[] a){ | |
arr = a; | |
} |
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 NumStatsArray{ | |
//Create a private array as a double as final | |
________________________________________ | |
public NumStatsArray(double[] a){ | |
arr = a; | |
} | |
//Iterate through and cancatenate all values except last and follow each with a comma. Creat string with a "{" the beginning and end it with a "}". |
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 NumStatsArray{ | |
//Create a private array as a double as final | |
________________________________________ | |
public NumStatsArray(double[] a){ | |
arr = a; | |
} | |
/* Iterate through and cancatenate all values except last and follow each with a comma. |
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 Vehicle | |
{ | |
//private integer to store the vehicle's location | |
private int __________; | |
public ________() | |
{ | |
location = ___; | |
} |
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; | |
class StringShortener { | |
public static void main(String[] args) { | |
//Declare scanner | |
Scanner scan = new Scanner(System.in); | |
//Get message from user input | |
System.out.println("Type the message to be shortened"); | |
String msg = scan.nextLine(); |
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
package dev.theturkey.aoc2020; | |
import java.util.List; | |
public class Day1 extends AOCPuzzle | |
{ | |
public Day1() | |
{ | |
super("1"); | |
} |
NewerOlder