Create a text file called t1_input.txt and it should contain the following data:
ID: 3713958 • Letter: C
Question
Create a text file called t1_input.txt and it should contain the following data: kscrivnor:1001:wheel, admin:/home/kscrivnor shamilton:1002:staff:/home/shamilton lmoody: 1003:staff:/home/lmoody error: 1x00: error:/home/error glowe: 1004: manager:/home/glowe Use the Scanner class to read the data from the file and separate by colons. Use printf to print the data in a "pretty" format. • For parsing, make sure you use the Scanner class. • Read in the second field as an int. • Catch the appropriate exceptions for the potential errors: o No such element (A field is blank) o Input type mismatch (The field does not match the type) Your output should match: /home/kscrivnor /home/shamilton kscrivnor 1001 wheel, admin shamilton 1002 staff *** Error, not enough data. lmoody 1003 staff *** Error, bad data format. glowe 1004 manager /home/lmoody /home/gloweExplanation / Answer
Task4.java
public class Task4 {
public static void main(String[] args) {
java.util.Scanner in = new java.util.Scanner(System.in);
System.out.print("Please Enter a string: ");
String str = in.nextLine();
boolean status = recursivePalindrome(str);
if(status){
System.out.println(str+" is a palindrome");
}
else{
System.out.println(str+" is not a palindrome");
}
}
public static boolean recursivePalindrome(String str){
// if length is 0 or 1 then String is palindrome
if(str.length() == 0 || str.length() == 1)
return true;
if(str.charAt(0) == str.charAt(str.length()-1))
return recursivePalindrome(str.substring(1, str.length()-1));
return false;
}
}
Output:
Please Enter a string: madam
madam is a palindrome
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.