Numbers with embedded dashes play a huge role in our lives. Think of your phone number or Social Security number. Write a program that uses a Scanner to take a single line of user input. You may assume this input consists of any number of characters and contains zero, one or two dashes. Use only String's indexOf, lastIndexOf, and substring methods. Sample input might be
123-45-6789
or
919-555-1212
or
hare-brained
Your program should remove the dashes and print the digits. The output for the above input would be
123456789
and
9195551212
and
harebrained
Program must haves:
import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner in=new Scanner(System.in);
String str;
System.out.println("User Input: ");
str=in.nextLine();
int indx1=str.indexOf("-");
int indx2=str.lastIndexOf("-");
String res="";
if(indx1==indx2)
{
res=str.substring(0, indx1)+str.substring(indx2+1);
}
else
{
res=str.substring(0, indx1)+str.substring(indx1+1,
indx2)+str.substring(indx2+1);
}
System.out.println(res);
}
}
Numbers with embedded dashes play a huge role in our lives. Think of your phone number...
!!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random text with my generateText method, you can move on to the second step. Create a third class called Generator within the cs1410 package. Make class. This class should have a main method that provides a user interface for random text generation. Your interface should work as follows: Main should bring up an input dialog with which the user can enter the desired analysis level...
Program Set 2 10 points) Credit card number validation Program Credit card numbers follow certain patterns: It must have between 13 and 16 digits, and the number must start with: 4 for Visa cards 5 for MasterCard credit cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card...