-1
Я написал следующий код, однако попытался выяснить, как его переписать, включив параметры и логические значения, если это возможно, когда основной метод запрашивает ввод пользователя, а затем вызывает методы для получения результата:Внедрение того же кода разными способами
import java.util.*;
class Congress
{
public static void main (String [] args)
{
int age, citizen, i, r;
citizen = 0;
i = 0;
r = 0;
age = -1;
Scanner keyboard = new Scanner(System.in);
System.out.println ("CONGRESS ELIGIBILITY");
for (age = -1; age < 0; r++)
{
System.out.println();
System.out.print ("Enter age of candidate: ");
age = keyboard.nextInt();
System.out.print ("Enter years of US citizenship: ");
citizen = keyboard.nextInt();
if (age <= 0)
{
System.out.print ("Please enter a proper age. ");
}
}
if (age >= 25 && citizen >= 7) {
i++;
}
if (age >= 30 && citizen >= 9) {
i++;
}
if (i == 0) {
System.out.println ("The candidate is not eligible for election to either the House of Representatives or the Senate.");
}
if (i == 1) {
System.out.println ("The candidate is eligible for election to the House of Representatives but is not eligible for election to the Senate.");
}
if (i == 2) {
System.out.println ("The candidate is eligible for election to both the House of Representatives and the Senate.");
}
}
}