import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
public class sentence {
public static void main() throws IOException {
InputStreamReader br = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(br);
System.out.println("Enter a sentence.");
String a = in.readLine();
String ar[] = new String[10000];
int k = 0;
try {
if (a.length() == 0) {
throw new NullError();
}
if ('a' < a.charAt(0) && a.charAt(0) < 'z') {
throw new CaseError();
}
if (a.charAt(a.length() - 1) != '.') {
throw new FullStopError();
}
int countuppercase = 0;
String s1 = "";
for (int i = 0; i < a.length(); i++) {
char c = a.charAt(i);
if (1 < countuppercase) {
throw new CaseError();
}
if (c != ' ' && c != '.') {
s1 = s1 + c;
} else {
ar[k] = s1;
k++;
s1 = "";
}
}
} catch (NullError e) {
System.out.println("You can't enter an empty string.");
} catch (CaseError e) {
System.out
.println("You have used the upper case and lower case properly.");
} catch (FullStopError e) {
System.out.println("You have forgot to use the full stop.");
}
for (int i = 0; i < k - 1; i++) {
String tmp = "";
for (int j = i; j < k - 1; j++) {
if (ar[j].length() > ar[j + 1].length()) {
tmp = ar[j];
ar[j] = ar[j + 1];
ar[j + 1] = tmp;
}
}
}
for (int i = 0; i < k; i++) {
System.out.print(ar[i]);
if (i < (k - 1)) {
System.out.print(" ");
} else
System.out.print(".");
}
}
}
class NullError extends Exception// If someone asks me what is name or purpose
// of defining this class what should I
// tell?
{
public NullError() {
}
}
class CaseError extends Exception {
public CaseError() {
}
}
class FullStopError extends Exception {
public FullStopError() {
}
}
For example if I write this code.
What is the name of a class which extends the Exception
class is it called an abstract class and what is its use?
This code arranges the words in sentence in increasing order of the number of letters, I implemented some custom exceptions which will be forcefully thrown, such as if there is no full stop. To throw a new exception we need to define a separate class with the same name. I don't understand what is the name of this class is it an abstract class and whats is purpose since I am only defining an empty constructor for the class.