mirror of
https://github.com/System-End/APCSA.git
synced 2026-04-19 16:38:24 +00:00
Lesson 3
This lesson was hard aaaaa \n Substrings and compareTo were not easy, understand them kinda tho yay!
This commit is contained in:
parent
4356feb6db
commit
d5e752d6e8
4 changed files with 62 additions and 0 deletions
13
U2/L3/U2_L3_Activity_Four.java
Normal file
13
U2/L3/U2_L3_Activity_Four.java
Normal 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(" "));
|
||||
}
|
||||
}
|
||||
17
U2/L3/U2_L3_Activity_One.java
Normal file
17
U2/L3/U2_L3_Activity_One.java
Normal 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
15
U2/L3/U2_L3_Activity_Three.java
Normal file
15
U2/L3/U2_L3_Activity_Three.java
Normal 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));
|
||||
}
|
||||
}
|
||||
17
U2/L3/U2_L3_Activity_Two.java
Normal file
17
U2/L3/U2_L3_Activity_Two.java
Normal 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));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue