How can I make this Java leap year program loop? -
i have make program tells if year leap year or not, class. have basic function of program done, want able ask user if want whole thing again (if enter yes, repeat program. if enter no, program terminate). preferably use while loops can't quite figure out how it. appreciated.
system.out.println("this program let enter year , tell you" + " if lear year"); int lyear; scanner scan = new scanner(system.in); system.out.println("enter valid gregorian year(greater 1581): "); lyear = scan.nextint(); boolean leapyear = ((lyear % 4 == 0) && (lyear % 100 != 0) || (lyear % 400 == 0)); if (lyear < 1582) { system.out.println("that not gregorian year"); } else if (leapyear) { system.out.println("that leap year"); } else { system.out.println("that not leap year"); } }
you may try proceed following code snippet -
while(scan.hasnext()){ line = scan.readline(); if(line.equalsignorecase("yes"){ continue; }esle{ try{ int number = integer.parseint(line); }catch(numberformatexception nfe){} } }
Comments
Post a Comment