diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89f9ac0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 0000000..966d5f5 --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 860c388..2d4d41d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ - + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/JavaIntro3Debrief/com/example/main/Main.class b/out/production/JavaIntro3Debrief/com/example/main/Main.class deleted file mode 100644 index 1c79707..0000000 Binary files a/out/production/JavaIntro3Debrief/com/example/main/Main.class and /dev/null differ diff --git a/src/com/example/main/Main.java b/src/com/example/main/Main.java index ebce634..b3e5c02 100644 --- a/src/com/example/main/Main.java +++ b/src/com/example/main/Main.java @@ -1,5 +1,6 @@ package com.example.main; +import java.util.ArrayList; import java.util.Arrays; class Main { @@ -12,46 +13,71 @@ public static void main(String[] args) { */ //create an array (not an ArrayList) called favoriteColors that holds five strings with your favoriteColors and print the entire array to the screen. - - //Change the third element of facoriteColors to a different color and print that element to the sceen - + String[] favoriteColors = {"Purple", "Black", "Crimson", "Cobalt", "Magenta"}; + System.out.println(Arrays.toString(favoriteColors)); + //Change the third element of favoriteColors to a different color and print that element to the sceen + favoriteColors[2] = "Purple again"; + System.out.println(favoriteColors[2]); //Declare and initialize and array of type int called numbers to hold 1000 elements (this should be used later in the loop exercise) //ArrayList //Declare and initialize an ArrayList so that it holds values of type . - + ArrayList doubles = new ArrayList<>(); //Using the .add() method, add 5 decimal values to the ArrayList and print it to the screen - + doubles.add(3.14); + doubles.add(2.89); + doubles.add(4.5); + doubles.add(6.67); + doubles.add(1.337); + System.out.println(doubles); //Using the .remove() method, remove the 3rd value in the ArrayList. - + doubles.remove(2); //Print ArrayList to the screen. - + System.out.println(doubles); //Now change the last element in the ArrayList and print the new element to the screen - + doubles.set(doubles.size()-1, 5.43); /* Some activities for Loops */ // write a for loop that prints out numbers 1-1000 and saves these numbers to the empty array you created earlier + int[] numbers = new int[1000]; - // write a while loop that prints the elements of the array you used in the previous exercise. Take care to avoid infinite looping! + for (int i = 0; i < 1000; i++) { + System.out.println(i+1); + numbers[i] = i+1; + } + System.out.println(Arrays.toString(numbers)); + // write a while loop that prints the elements of the array you used in the previous exercise. Take care to avoid infinite looping! + int index = 0; + while(index0); // write an enhanced for loop that iterates over this array and prints the result of that number modulus(%) 3 - + for (int i : + numbers) { + System.out.println(i%3); + } /* Some activities for String methods */ // Create two String variables, one holding "Hello" and one holding "world" - + String hello = "Hello"; + String world = "world"; // using String methods, concatenate these strings together with a space between them so that it reads "Hello world" and save the resulting String to a new variable - + String helloWorld = hello.concat(" ").concat(world); // then, create a for loop that iterates over your new String and prints each letter out using sout - + for (int i = 0; i