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.nextString();
inputDay = scnr.nextInt();
String season;
if(inputMonth == "April","May","June"){
String season = "Spring";
}else if(inputMonth == "July","August","September"){
String season = "Summer";
}else if(inputMonth == "October","November","December"){
String season = "Autumn";
}else if(inputMonth == "January","February","March"){
System.out.println("Winter");
}else{
System.out.println("Invalid");
}
if((inputMonth == "March") && (inputDay >= 20)){
String season = "Spring";
}else if((inputMonth == "June") && (inputDay >=
21)){
String season = "Summer";
}else if((inputMonth == "September") && (inputDay >=
22)){
String season = "Autumn";
}else if((inputMonth == "December") && (inputDay >=
20)){
String season = "Winter";
}
System.out.println(season);
}
}
I was wondering why my code isn't working.
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String inputMonth = scnr.next();
int inputDay = scnr.nextInt();
if (inputMonth.equals("January") && inputDay >= 1 && inputDay <= 31)
System.out.println("Winter");
else if (inputMonth.equals("February") && inputDay >= 1 && inputDay <= 29)
System.out.println("Winter");
else if (inputMonth.equals("April") && inputDay >= 1 && inputDay <= 30)
System.out.println("Spring");
else if (inputMonth.equals("May") && inputDay >= 1 && inputDay <= 30)
System.out.println("Spring");
else if (inputMonth.equals("July") && inputDay >= 1 && inputDay <= 31)
System.out.println("Summer");
else if (inputMonth.equals("August") && inputDay >= 1 && inputDay <= 31)
System.out.println("Summer");
else if (inputMonth.equals("October") && inputDay >= 1 && inputDay <= 31)
System.out.println("Autumn");
else if (inputMonth.equals("November") && inputDay >= 1 && inputDay <= 30)
System.out.println("Autumn");
else if (inputMonth.equals("March") && inputDay >= 20 && inputDay <= 31)
System.out.println("Spring");
else if (inputMonth.equals("June") && inputDay >= 1 && inputDay <= 20)
System.out.println("Spring");
else if (inputMonth.equals("June") && inputDay >= 21 && inputDay <= 30)
System.out.println("Summer");
else if (inputMonth.equals("September") && inputDay >= 1 && inputDay <= 21)
System.out.println("Summer");
else if (inputMonth.equals("September") && inputDay >= 22 && inputDay <= 30)
System.out.println("Autumn");
else if (inputMonth.equals("December") && inputDay >= 0 && inputDay <= 20)
System.out.println("Autumn");
else if (inputMonth.equals("December") && inputDay >= 21 && inputDay <= 30)
System.out.println("Winter");
else if (inputMonth.equals("March") && inputDay >= 1 && inputDay <= 19)
System.out.println("Winter");
else
System.out.println("Invalid");
}
}
import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new...
import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //ask the user for a temperature System.out.println("Enter a temperature:"); double temp = scnr.nextDouble(); //ask the user for the scale of the temperature System.out.println("Is that Fahrenheit (F) or Celsius (C)?"); char choice = scnr.next().charAt(0); if(choice == 'F') { //convert to Celsius if given temperature was Fahrenheit System.out.println(temp + " degrees Fahrenheit is " + ((5.0/9) * (temp-32)) + " degrees Celsius"); } else {...
import java.util.Scanner; public class Age { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int a; System.out.println("Input your age"); a = sc.nextInt(); boolean mess = isAllowed(a); String mess2 = ?isAllowed(a)return"You are allowed to vote";:"You arent allowed"; String age = personAge(a); personAge(a); } public static String personAge(int age) { String mess = ""; if(age<18) return mess = "You are minor"; else if(age>=18 && age<=22) return mess = "You are legal you can vote"; else if(age>=22 && age<=60) return...
Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){ Scanner kb = new Scanner(System.in); System.out.println("Enter a word:"); String word = kb.next(); String reverse = ""; for (int i=word.length()-1; i>=0; i--) reverse += word.charAt(i); boolean result = reverse.equalsIgnoreCase(word); if (result) System.out.println("The word " +word+ " is a Palindrome."); else System.out.println("The word " +word+ " is not a Palindrome."); } } Rewrite the program so that the main method is: public static void...
import java.util.Scanner; public class TriangleMaker { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle."); Scanner keyboard = new Scanner(System.in); int size = keyboard.nextInt(); for (int i = 1; i <= size; i++) { for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } for (int...
*This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int numCount = scnr.nextInt(); int[] Array = new int[numCount]; for(int i = 0; i < numCount; ++i) { Array[i] = scnr.nextInt(); } int jasc = Array[0], gws = Array[1], numbers, tempo; if (jasc > gws) { tempo = jasc; jasc...
import java.util.Scanner; public class SieveOfEratosthenes { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number"); int num = sc.nextInt(); boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false;...
import java.util.Scanner;
public class Lab6d {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// TODO: get user choice
// TODO: call printTable method passing choice as the
parameter
}
public static void printTable(int stop) {
// TODO: print header
// TODO: loop to print table rows up to stop value
}
Write a Java program where the main () method prompts the user to select an integer value between 1 and...
import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...
import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 { public static void main(String[] args) { String name; String answer; int correct = 0; int incorrect = 0; Scanner phantom = new Scanner(System.in); System.out.println("Hello, What is your name?"); name = phantom.nextLine(); System.out.println("Welcome " + name + "!\n"); System.out.println("My name is Danielle Brandt. " +"This is a quiz program that...
import java.util.Scanner; public class Client{ public static void main(String args[]){ Coin quarter = new Coin(25); Coin dime = new Coin(10); Coin nickel = new Coin(5); Scanner keyboard = new Scanner(System.in); int i = 0; int total = 0; while(true){ i++; System.out.println("Round " + i + ": "); quarter.toss(); System.out.println("Quarter is " + quarter.getSideUp()); if(quarter.getSideUp() == "HEADS") total = total + quarter.getValue(); dime.toss(); System.out.println("Dime is " + dime.getSideUp()); if(dime.getSideUp() == "HEADS") total = total +...