lundi 29 novembre 2021

How to continue an if else statement (?) with another if else statement

A little confused on where to put another if-else statement after one. like do I put it under the if statement ("have you registered to vote yet?" ) or do i put it under the else statement?

I wanted it to answer if yes then it would print out "you can vote" and if no then it would print out "You must register before you can vote"

here's the code

import java.util.Scanner;

public class voting {
  public static void main(String[] args) {
    int yourage, votersage;
    votersage = 18;
    Scanner input = new Scanner(System.in);
    System.out.println("How old are you? ");
    yourage = input.nextInt();
    if (yourage >= votersage) {
      System.out.println("Have you registered to vote?");
    }
    else {
      System.out.println("You are too young to vote");
    }
  }
}

Aucun commentaire:

Enregistrer un commentaire