You’ll write a poem in this program. However, there are two types of poems you’l
ID: 3771217 • Letter: Y
Question
You’ll write a poem in this program. However, there are
two types of poems you’ll have to print out: Haikus and Acrostics.
First, ask the user for 2 booleans.
Do you want to hear a haiku? (true/false)
Do you want to hear an acrostic? (true/false)
Then, based on the answers from the user, output a haiku, acrostic, both, or neither.
Be sure your haiku is 3 lines long and your acrostic 5 lines long.
Your program will will output a total of 12 lines if both poems are printed. 8 lines from the poems and 4 lines from reading the user input.
Explanation / Answer
import java.util.*;
class poem
{
public static void main(String args[])
{
boolean ans1, ans2;
Scanner scan=new Scanner(System.in);
System.out.println("Do you want to hear a haiku? (true/false) ");
ans1=scan.nextBoolean();
System.out.println("Do you want to hear an acrostic? (true/false) ");
ans2=scan.nextBoolean();
if(ans1)
{
System.out.println("aaa");
System.out.println("bbb");
System.out.println("ccc");
}
if(ans2)
{
System.out.println("aaa");
System.out.println("bbb");
System.out.println("ccc");
System.out.println("ddd");
System.out.println("eee");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.