import java.util.Scanner; public class BranchLoopExample { public static void main(String [] args) { Scanner in = new Scanner(System.in); float percent = -1; boolean quit = false; String answer; do { System.out.print("Term % score: "); percent = in.nextFloat(); if ((percent >= 0) && (percent <= 49)) System.out.println("F"); else if ((percent >= 50) && (percent <= 59)) System.out.println("D"); else if ((percent >= 60) && (percent <= 69)) System.out.println("C"); else if ((percent >= 70) && (percent <= 79)) System.out.println("B"); else if ((percent >= 80) && (percent <= 100)) System.out.println("A"); else System.out.println("Error"); System.out.print("Quit program ('y' = yes): "); in.nextLine(); // Remove newline after user input answer = in.nextLine(); if (answer.length() > 0) // If user types in no data and hits enter by mistake { if ((answer.charAt(0) == 'y') || (answer.charAt(0) == 'Y')) quit = true; } } while(quit == false); } }