-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a09cd13
commit 30b3b9a
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import java.util.Scanner; | ||
|
||
public class NameParser { | ||
public static void main(String[] args) { | ||
Scanner keyboard = new Scanner(System.in); | ||
|
||
String fullName; | ||
String firstName; | ||
String lastName; | ||
|
||
System.out.println("What is your full name?"); | ||
fullName = keyboard.nextLine(); | ||
|
||
int indexOfSpace = fullName.indexOf(" "); | ||
|
||
firstName = fullName.substring(0, indexOfSpace); | ||
lastName = fullName.substring(indexOfSpace + 1); | ||
|
||
firstName = firstName.toUpperCase(); | ||
lastName = lastName.toLowerCase(); | ||
|
||
System.out.println("First name is " + firstName); | ||
System.out.println("Last name is " + lastName); | ||
}//end main | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
import java.lang.reflect.Array; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class Proj5_1_NamePermutations { | ||
public static void main(String[] args) { | ||
ArrayList<String> firstNames = new ArrayList<>(); | ||
ArrayList<String> lastNames = new ArrayList<>(); | ||
|
||
Scanner keyboard = new Scanner(System.in); | ||
String fullName; | ||
String firstName; | ||
String lastName; | ||
int indexOfSpace; | ||
|
||
final int NUM_NAMES = 5; | ||
|
||
for(int i = 0; i < NUM_NAMES; i++) { | ||
System.out.print("Please enter name " + i + "\t"); | ||
fullName = keyboard.nextLine(); | ||
indexOfSpace = fullName.indexOf(" "); | ||
firstName = fullName.substring(0, indexOfSpace); | ||
lastName = fullName.substring(indexOfSpace + 1); | ||
|
||
firstNames.add(firstName); | ||
lastNames.add(lastName); | ||
}//end for | ||
|
||
//now for the permutations | ||
|
||
for(int i = 0; i < firstNames.size(); i++) { | ||
for(int j = 0; j < lastNames.size(); j++) { | ||
System.out.print(firstNames.get(i) + " "); | ||
System.out.println(lastNames.get(j)); | ||
}//end for j | ||
}//end for i | ||
}//end main | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
|
||
public class StringBuilderFun { | ||
public static void main(String[] args) { | ||
StringBuilder sb = new StringBuilder("John Baugh"); | ||
|
||
sb.append(" is awesome"); | ||
System.out.println(sb); | ||
|
||
sb.insert(5, "Phillip "); | ||
System.out.println(sb); | ||
|
||
sb.replace(22, 29, "amazing"); | ||
System.out.println(sb); | ||
|
||
sb.delete(5, 13); | ||
System.out.println(sb); | ||
|
||
sb.replace(0,4, "Dr."); | ||
|
||
System.out.println(sb); | ||
|
||
}//end main | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
|
||
public class StringMethods1 { | ||
public static void main(String[] args) { | ||
String name = "John Baugh"; | ||
String name2 = "John Baugh"; | ||
String name3 = "Rob Percival"; | ||
String challengeName = "Ed Mortram"; | ||
|
||
for(int i = 0; i < name.length(); i++) { | ||
System.out.print(name.charAt(i) + " "); | ||
}//end for | ||
|
||
System.out.println(); | ||
|
||
if(name.equals(name2)) { | ||
System.out.println("Names are equal."); | ||
} | ||
else { | ||
System.out.println("Names aren't equal."); | ||
} | ||
|
||
if(name.compareTo(name3) > 0) { | ||
System.out.println("name > name3"); | ||
} | ||
else { | ||
System.out.println("name <= name3"); | ||
} | ||
|
||
System.out.println("Comparing for the lecture challenge"); | ||
if (challengeName.compareTo(name) > 0) { | ||
System.out.println(challengeName + " is greater than " + name); | ||
} | ||
else { | ||
System.out.println(challengeName + " is less than or equal to " + name); | ||
} | ||
}//end main | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
public class StringMethods2 { | ||
public static void main(String[] args) { | ||
String myName = "John Baugh"; | ||
|
||
String upper = myName.toUpperCase(); | ||
String lower = myName.toLowerCase(); | ||
|
||
int whereIsB = myName.indexOf("B"); | ||
|
||
String lastName = myName.substring(5); | ||
|
||
System.out.println("upper is " + upper); | ||
System.out.println("lower is " + lower); | ||
System.out.println("B is at index " + whereIsB); | ||
System.out.println("Last name is " + lastName); | ||
}//end main | ||
} |