i would like to enter a string like ciphercloud and the ranges are 3 to 6 then it will shows like pher***.ranges are must be integers only if you give ranges as character it will never accept and also ranges must be positive integers only not be negative. by satisfying all this i coded like this way
class maskchar
{
public static void main(String args[])
{
String str = args[0];
int start = Integer.parseInt(args[1]);
int end = Integer.parseInt(args[2]);
char[] str1 = str.toCharArray();
int len = str1.length;
if((start >= 0 && start <= len) && (end >= 0 && end <= len))
{
for(int i = 0; i < start - 1; i++)
{
System.out.print("*");
}
for(int j = start - 1; j < end; j++)
{
System.out.print(str1[j]);
}
for(int k = end; k < len; k++)
{
System.out.print("*");
}
}
}
}
whenever we run this code it shows expected out put but if i pass character as starting range it will through an exception i.e NumberFormatException how can i handle that Exception and how can i make this as more flexible.