This is just a part of my code. The same structure goes for all 6 variables. (except level). Once read in, this prints back the input calculating the bonus. Bonus should be 0 at 10, cumulative +1 for each even number above 10 and -1 for each odd number below 10. How can i terminate if invalid input is entered. Do i have to use an if condition for all the inputs..
import java.util.Scanner;
public class Game{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int bonus,x;
double HP;
System.out.print("Enter Str : ");
int Str = sc.nextInt();
System.out.print("Enter Dex : ");
int Dex = sc.nextInt();
System.out.print("Enter Con : ");
int Con = sc.nextInt();
System.out.print("Enter Int : ");
int Int = sc.nextInt();
System.out.print("Enter Wis : ");
int Wis = sc.nextInt();
System.out.print("Enter Cha : ");
int Cha = sc.nextInt();
System.out.print("Enter Level : ");
int Level = sc.nextInt();
System.out.println("\nLevel : "+Level);
if ( Str == 10 ) {
bonus = 0;
System.out.println("Str : "+Str+"["+bonus+"]");
}
else if ( Str < 10 && Str % 2 == 0 ) {
bonus = 0 ;
for ( x = Str; x <= 10; x++ ) {
if ( x % 2 != 0 ) {
bonus = bonus + 1 ;
}
}
System.out.println("Str : "+Str+"[+"+bonus+"]");
}
else if ( Str < 10 && Str % 2 != 0 ) {
bonus = 0 ;
for ( x = Str; x <= 10; x++ ) {
if ( x % 2 == 0 ) {
bonus = bonus + 1 ;
}
}
System.out.println("Str : "+Str+"[-"+bonus+"]");
}
else if ( Str > 10 && Str % 2 == 0 ) {
bonus = 0 ;
for ( x = 10; x <= Str; x++ ) {
if ( x % 2 != 0 ) {
bonus = bonus + 1 ;
}
}
System.out.println("Str : "+Str+"[+"+bonus+"]");
}
else if ( Str > 10 && Str % 2 != 0 ) {
bonus = 0 ;
for ( x = 10; x <= Str; x++ ) {
if ( x % 2 == 0 ) {
bonus = bonus + 1 ;
}
}
System.out.println("Str : "+Str+"[-"+bonus+"]");
}