mirror of
https://github.com/System-End/APCSA.git
synced 2026-04-19 16:38:24 +00:00
U2 lesson 4
This commit is contained in:
parent
d5e752d6e8
commit
5420c97f30
2 changed files with 39 additions and 0 deletions
23
U2/L4/U2_L4_Activity_One.java
Normal file
23
U2/L4/U2_L4_Activity_One.java
Normal 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));
|
||||
}
|
||||
}
|
||||
16
U2/L4/U2_L4_Activity_Two.java
Normal file
16
U2/L4/U2_L4_Activity_Two.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue