Session 9
Source Code
import java.util.*;
public class Session9 {
public static void main(String[] args) {
System.out.println("Session 9");
// Example 1
// Example 2
// Example 3
// Example 4
// Example 5
// Example 6
// Example 7
// Example 8
// Example 9
// Example 10
// Example 11
// Example 12
// Example 13
// Example 14
// Example 15
}
}S9Problem1.java
import java.util.*;
public class S9Problem1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Problem 1");
}
}S9Problem2.java
import java.util.*;
public class S9Problem2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Problem 2");
}
}S9Problem3.java
import java.util.*;
public class S9Problem3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Problem 3");
}
}EmailDomain.java
import java.util.*;
public class EmailDomain
{
public static String getDomain(String email)
{
// TODO: Use indexOf and substring only.
// Example: "[email protected]" → "school.edu"
String domain;
return domain;
}
public static void main(String[] args)
{
// Do not change main!
Scanner in = new Scanner(System.in);
String email = in.nextLine();
System.out.println("Domain: " + getDomain(email));
in.close();
}
}
FileExtension.java
import java.util.*;
public class FileExtension
{
public static String getExtension(String fileName)
{
// TODO: Use indexOf and substring only.
// Example: "photo.jpeg" → "jpeg"
String ext;
return ext;
}
public static void main(String[] args)
{
// Do not change main!
Scanner in = new Scanner(System.in);
String fileName = in.nextLine();
System.out.println("Extension: " + getExtension(fileName));
in.close();
}
}
FirstSentence.java
import java.util.*;
public class FirstSentence
{
public static String getFirstSentence(String paragraph)
{
// TODO: Use indexOf and substring only.
// Assume sentences end with a period '.'
// Return everything up to and including the first '.'
// Example:
// "Today is Monday. We have class." → "Today is Monday."
String first;
return first;
}
public static void main(String[] args)
{
// Do not change main!
Scanner in = new Scanner(System.in);
String paragraph = in.nextLine();
System.out.println("First sentence: " + getFirstSentence(paragraph));
in.close();
}
}
AreaCode.java
import java.util.*;
public class AreaCode
{
public static String getAreaCode(String phone)
{
// TODO: Use indexOf and substring only.
// Assume the phone number format is "(###) ###-####"
// Example: "(212) 000-0000" → "212"
String code;
return code;
}
public static void main(String[] args)
{
// Do not change main!
Scanner in = new Scanner(System.in);
String phone = in.nextLine();
System.out.println("Area code: " + getAreaCode(phone));
in.close();
}
}
SecretPhrase.java
import java.util.*;
public class SecretPhrase
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
// The secret phrase
String secret = null;
// --- Step 1: Give the user hints ---
// --- Step 2: Let the user ask questions ---
// --- Step 3: Let the user guess the phrase ---
// --- Step 4: Compare using equals()
in.close();
}
}
Last updated
Was this helpful?