subject

Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day.

Ex: If the input is April 11, the output is:

spring
In addition, check if the string and int are valid (an actual month and day).

Ex: If the input is invalid, the output is:

invalid
The dates for each season are:
spring: March 20 - June 20
summer: June 21 - September 21
autumn: September 22 - December 20
winter: December 21 - March 19

My code is constantly outputting 'invalid, regardless of the date input.

import java. util. Scanner;

public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System. in);
String inputMonth;
int inputDay;

inputMonth = scnr. next();
inputDay = scnr. nextInt();
if((inputMonth=="March"&&in putDay>19)||inputMonth=="April"| |inputMonth=="May"||(inputMonth=="J une"&&inputDay<21))
{
System. out. println("spring");
}
else if((inputMonth=="June"&&inp utDay>20)||inputMonth=="July"||i nputMonth=="August"||(inputMonth==" September"&&inputDay<22) )
{
System. out. println("summer");
}
else if((inputMonth=="September"&&am p;inputDay>21)||inputMonth=="Oct ober"||inputMonth=="November"||(inp utMonth=="December"&&inputD ay<21))
{
System. out. println("autumn");
}
else if((inputMonth=="December"&& ;inputDay>20)||inputMonth=="Janu ary"||inputMonth=="February"||(inpu tMonth=="March"&&inputDay&l t;20))
{
System. out. println("winter");
}
else
{
System. out. println("invalid");

} }
}

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:00, dondre54
in 2007, floridians died in alcohol-related collisions.a.  501b.  1,051c.  5,015d.  10,839
Answers: 1
image
Computers and Technology, 22.06.2019 15:00, 2alshawe201
The three logical operators used to write compound conditions are "and," "or," and "not." a: true b: false
Answers: 2
image
Computers and Technology, 23.06.2019 09:30, ranmmm
The place where the extended axis of the earth would touch the celestial sphere is called the celestial
Answers: 1
image
Computers and Technology, 23.06.2019 12:00, xojade
Which of these is an example of an integrated presentation? a. a table created in powerpoint b. an image pasted into powerpoint c. a caption created in powerpoint d. an excel chart pasted into powerpoint
Answers: 1
You know the right answer?
Write a program that takes a date as input and outputs the date's season. The input is a string to r...

Questions in other subjects:

Konu
Mathematics, 21.05.2020 02:05
Konu
Mathematics, 21.05.2020 02:05