Given the following code (see below) how do you make it sothat only y lets you s
ID: 3613048 • Letter: G
Question
Given the following code (see below) how do you make it sothat only y lets you start another calender and enter month, etc.,while n ends the program. Otherwise it just asks the questionagain.------------ Relevant section of code:
System.out.print("Would you like another (y/n)? "); another=stdIn.next().charAt(0); }while(another!='Y'&& another=='y'); Given the following code (see below) how do you make it sothat only y lets you start another calender and enter month, etc.,while n ends the program. Otherwise it just asks the questionagain.
------------ Relevant section of code:
System.out.print("Would you like another (y/n)? "); another=stdIn.next().charAt(0); }while(another!='Y'&& another=='y');
Explanation / Answer
please rate - thanks in the main program new code inred import java.util.*; public class calendar {public static void main(String[] args) {int month=0,year; char choice; Scanner in =new Scanner(System.in); do { while(month12) { System.out.println("Enter Month (1-12): "); month=in.nextInt(); } System.out.println("Enter Year: "); year=in.nextInt(); print(month-1,year); month=0; do{ System.out.println("Would you likeanother calendar (y/n)?"); choice=in.next().charAt(0); if(choice!='y'&&choice!='Y'&&choice!='n'&&choice!='N') System.out.println("invalidchoice"); }while(choice!='y'&&choice!='Y'&&choice!='n'&&choice!='N'); }while(choice!='Y'&& choice=='y'); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.