U2 lesson 4

This commit is contained in:
End Nightshade 2026-02-05 10:27:46 -07:00
parent d5e752d6e8
commit 5420c97f30
No known key found for this signature in database
2 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,23 @@
import java.util.Scanner;
public class U2_L4_Activity_One {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// get first string
System.out.println("Enter first string");
String s1 = scanner.nextLine();
// get second string
System.out.println("Enter second string");
String s2 = scanner.nextLine();
//Get number of letters to use from each string
System.out.println("Enter number of letters from each word");
int n = scanner.nextInt();
// print last n letters of first string combined with first n letters of s2
System.out.println(s1.substring(s1.length() - n) + s2.substring(0, n));
}
}

View file

@ -0,0 +1,16 @@
/* Lesson 4 Coding Activity Question 2 */
import java.util.Scanner;
public class U2_L4_Activity_Two {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str1 = scan.nextLine();
String str2 = new String(str1);
str1 = str1.toUpperCase();
str2 = str2.substring(0, 1).toUpperCase() + str2.substring(1);
System.out.println(str2);
System.out.println(str1);
}
}