07:31Java substrings are easy! 📧
From the creator
#java #javatutorial #javacourse This is a beginner's introduction to substrings and we'll use it to code an email slicer that extracts a username and domain from an email address. import java.util.Scanner; public class Main { public static void main(String[] args) { // .substring() = A method used to extract a portion of a string // .substring(start, end) Scanner scanner = new Scanner(System.in); String email; String username; String domain; System.out.print("Enter your email: "); email = scanner.nextLine(); if(email.contains("@")){ username = email.substring(0, email.indexOf("@")); domain = email.substring(email.indexOf("@") + 1); System.out.println(username); System.out.println(domain); } else{ System.out.println("Emails must contain @"); } scanner.close(); } }
Published 2024-12-05 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.





