Computers and Technology, 14.06.2021 02:50, oaaliyah505
I need this answered in JAVA:
Primary U. S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. Auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. Thus, I-405 services I-5, and I-290 services I-90.
Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west.
Ex: If the input is:
90
the output is:
I-90 is primary, going east/west.
Ex: If the input is:
290
the output is:
I-290 is auxiliary, serving I-90, going east/west.
Ex: If the input is:
0
or any number not between 1 and 999, the output is:
0 is not a valid interstate highway number.
Ex: If the input is:
200
the output is:
200 is not a valid interstate highway number.
This is what I've got so far- but I'm not really understanding fully...
import java. util. Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System. in);
int highwayNumber;
int primaryNumber;
highwayNumber = scnr. nextInt();
if ((highwayNumber >= 1) && (highwayNumber <= 999)) {
if (highwayNumber <= 99) {
if (highwayNumber %2 == 0) { //recognizes even numbers
System. out. printf("I-%d is primary, going east/west.\n", highwayNumber);
}
else {
System. out. printf("I-%d is primary, going north/south.\n", highwayNumber); //recognizes other than even numbers
}
}
else {
primaryNumber = highwayNumber;
highwayNumber %= 100; //what does this mean?
if (highwayNumber % 2 == 0) { //recognizes even numbers
System. out. printf("I-%d is auxiliary, serving the I-%d, going east/west.\n", primaryNumber, highwayNumber);
}
else {
System. out. printf("I-%d is auxiliary, serving the I-%d, going north/south.\n", primaryNumber, highwayNumber);
}
}
} else {
System. out. printf("%d is not a valid interstate highway number.\n", highwayNumber);
}
}
}
This answer is incomplete, because when I input 200, the out put is:
I-200 is auxiliary, serving the I-0, going east/west.
it should be:
200 is not a valid interstate highway number.
Answers: 2
Computers and Technology, 24.06.2019 00:00, miguelturner
Which tool could be used to display only rows containing presidents who served two terms
Answers: 3
Computers and Technology, 24.06.2019 07:30, Isabellawuzhere
Aproject involves many computing systems working together on disjointed task towards a single goal what form of computing would the project be using
Answers: 3
Computers and Technology, 24.06.2019 07:40, daebreonnakelly
What type of multimedia are live news feeds? live news feeds are examples of multimedia.
Answers: 2
Computers and Technology, 24.06.2019 12:00, elainnysanchez1541
How can we take picture in this app
Answers: 1
I need this answered in JAVA:
Primary U. S. interstate highways are numbered 1-99. Odd numbers (lik...
Mathematics, 26.03.2021 02:10
Mathematics, 26.03.2021 02:10
Computers and Technology, 26.03.2021 02:10
Mathematics, 26.03.2021 02:10
Mathematics, 26.03.2021 02:10
Mathematics, 26.03.2021 02:10
Mathematics, 26.03.2021 02:10