This is the code:
public class Pr3
{
public Pr3 ()
{
String x = "";
String Line = "";
Scanner sc = new Scanner (System.in);
do
{
System.out.println ("Please enter your sentence");
String NewLine = sc.nextLine();
Line = Line + " " + NewLine;
System.out.println ("Your new Line is: " + Line);
System.out.println ("Do you want to enter a new sentence? Enter Y for yes and N for no");
x = sc.next();
} while (!"N".equals(x) && "Y".equals(x));
exit(0);
}
}
And this is the output:
- Please enter your sentence
- Hagar
- Your new Line is: Hagar
- Do you want to enter a new sentence? Enter Y for yes and N for no
- Y
- Please enter your sentence
- Your new Line is: Hagar
- Do you want to enter a new sentence? Enter Y for yes and N for no