The program asks the user to enter a string with at least 5 letters. It then stores the string in a variable called s. It creates three new variables: first is set to the first letter of s, second is set to the second letter, and next is set to the substring from the third to fifth letters. The program then prints the values of the three variables in the specified format.
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
write a program that- Asks the user to enter a string that contains at.docx
1. write a program that: Asks the user to enter a string that contains at least five letters. Stores that
number into a variable called s. Creates a variable called "first", and sets it equal to the first
letter of s. Creates a variable called "second", and sets it equal to the second letter of s. Creates
a variable called "next", and sets it equal to the string that consists of the third, fourth, and fifth
letter of s. Prints out the values of variables first, second, next, using EXACTLY the same format
as shown below. For example: if the user enters the string "DeQ81", your program output
should look EXACTLY like this: Please enter a string, at least 5 letters long: DeQ81 The first
letter of s is D. The second letter of s is e. The third, fourth, and fifth letters are Q81.
Solution
Assuming the languge to be java
import java.util.Scanner;
public class substring {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s;
System.out.print("Please enter a string, at least 5 letters long: ");
s=sc.next();
System.out.print(" The first letter of s is "+s.charAt(0)+". ");
System.out.print(" The second letter of s is "+s.charAt(1)+". ");
System.out.print(" The third, fourth, and fifth letters are "+s.substring(2, 5)+". ");
}
}
run:
Please enter a string, at least 5 letters long: DeQ81
The first letter of s is D.
The second letter of s is e.
The third, fourth, and fifth letters are Q81.