This lesson was hard aaaaa \n Substrings and compareTo were not easy, understand them kinda tho yay!
This commit is contained in:
End Nightshade 2026-02-03 10:15:10 -07:00
parent 4356feb6db
commit d5e752d6e8
No known key found for this signature in database
4 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,13 @@
/* Lesson 3 Coding Activity Question 4 */
import java.util.Scanner;
public class U2_L3_Activity_Four {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a sentence");
String sentence = scan.nextLine();
System.out.println(sentence.indexOf(" "));
}
}

View file

@ -0,0 +1,17 @@
/* Lesson 3 Coding Activity Question 1 */
import java.util.Scanner;
public class U2_L3_Activity_One {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a string:");
String item = scan.nextLine();
System.out.println("Enter a number:");
int n = scan.nextInt();
System.out.println(
item.substring(0, n) + item.substring(item.length() - n)
);
}
}

View file

@ -0,0 +1,15 @@
/* Lesson 3 Coding Activity Question 3 */
import java.util.Scanner;
public class U2_L3_Activity_Three {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter first word:");
String one = scan.nextLine().toLowerCase();
System.out.println("Enter second word:");
String two = scan.nextLine().toLowerCase();
System.out.println("Result: " + one.compareTo(two));
}
}

View file

@ -0,0 +1,17 @@
/* Lesson 3 Coding Activity Question 2 */
import java.util.Scanner;
public class U2_L3_Activity_Two {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a string:");
String word = scan.nextLine();
System.out.println(
"How many characters would you like to delete at the end?"
);
int del = scan.nextInt();
System.out.println(word.substring(0, word.length() - del));
}
}