Ask the user for a number between 1 and 11 stop asking when
Ask the user for a number between 1 and 11; stop asking when the user enters 0 OR when the total goes over 21. Display the total on the screen. For example:
if input is over 12 display \"Please follow directions!\"
Solution
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author USER
*/
import java.util.*;
public class total
{
public static void main(String args[])
{
int tot=0,n;
System.out.println(\"Enter the Number Between 1 to 11:\");
Scanner scan=new Scanner(System.in);
n=scan.nextInt();
for(int i=1;i<=n;i++)
{
tot=tot+n;
if(n==0||tot>21)
{
System.out.println(\"Total:\"+tot);
System.out.println(\"Thank you for playing!!!\");
System.exit(tot);
}
else
if(n==12)
{
System.out.println(\"Please follow directions!\");
}
System.out.println(\"Enter the Number Between 1 to 11:\");
n=scan.nextInt();
}
}
}
