A dooblefleck is a string that conforms to the following format: Write Java code
ID: 3536436 • Letter: A
Question
A dooblefleck is a string that conforms to the following format:
Write Java code that will obtain a string from the user and then test to see if it is a valid dooblefleck producing appropriate output to the user in either case.
For example the following two strings would be valid doobleflecks BZ8#977-w3.ed 123#hdw-aU.ed
The following would not be a valid dooblefleck d123#hdw-aU.e
Ensure that you write appropriate methods as part of your solution which utilise appropriate parameter passing.
Make sure that you use appropriate user prompts and labels for all output to the screen.
Use Eclipse to create your project and class file. When creating the class use the name that was given above.
Explanation / Answer
import java.io.*;
public class Test{
public static void main(String args[]){
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String Str1 = new String();
System.out.println("enter the dooblefleck");
try{Str1=in.readLine();}
catch(Exception e){};
int flag=1;
char char1=Str1.charAt(3);
char char2=Str1.charAt(7);
char char3=Str1.charAt(8);
char char4=Str1.charAt(10);
char char5=Str1.charAt(11);
char char6=Str1.charAt(12);
if((Str1.length()!=13)||(char1!='#')||(char2!='-')||(!Character.isLowerCase(char3))||(char4!='.')||(char5!='e')||(char6!='d'))
flag =0;
if(flag==1){
System.out.println("The dooblefleck is a valid string ");}
else{
System.out.println("The dooblefleck is not a valid string");}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.