Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do you convert this to else if statements for java * To change this license

ID: 3754977 • Letter: H

Question

How do you convert this to else if statements for java

* To change this license header, choose License Headers in Project Properties * To change this template file, choose Tools | Templates * and open the template in the editor. package chinesezodiac; import java.util.scanner; * gauthor ekose public class Chinesezodiac f *Eparam args the command line arguments public static void main(String[] args) 1t Scanner xnew Scanner (System.in); // Declaring a new scanner System.out.print("enter a year (year can't be negative): "); int year, zodiac; year-.nextInt();//request an integer from users if (yearce)t System.out.println("You can't enter a negative year" System.exit1); elsef zodiac-year12 switch(zodiac)I case e: System.out.println("Monkey"); break; case 1 System.out.println("Rooster"); break; case 2 System.out.println("Dog); break; case 3: System.out.println("Pig"); break; case 4: System.out.println("Rat"); break; case 5 System. out . printin ( "Ox" ) ; break; case 6 System.out.println("Tiger"); break; case 7: System.out.println("Rabbit"); break; case 8 System.out.println("Dragon"); break; case 9 System.out.println("Snake"); break; System.out.println("Horse"); System.out.println("Sheep"); case 1e: case 11: break;

Explanation / Answer

import java.util.Scanner; public class ChineseZodiac { public static void main(String[] args) { Scanner x = new Scanner(System.in); System.out.println("enter a year (can't be negative): "); int year, zodiac; year = x.nextInt(); if(year < 0) { System.out.println("You can't enter a negative year"); System.exit(1); } else { zodiac = year % 12; if (zodiac == 0) System.out.println("Monkey"); else if (zodiac == 1) System.out.println("Rooster"); else if (zodiac == 2) System.out.println("Dog"); else if (zodiac == 3) System.out.println("Pig"); else if (zodiac == 4) System.out.println("Rat"); else if (zodiac == 5) System.out.println("Ox"); else if (zodiac == 6) System.out.println("Tiger"); else if (zodiac == 7) System.out.println("Rabbit"); else if (zodiac == 8) System.out.println("Dragon"); else if (zodiac == 9) System.out.println("Snake"); else if (zodiac == 10) System.out.println("Horse"); else if (zodiac == 11) System.out.println("Sheep"); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote