Jump to content

Can I ask about Java coding in this page?

o0NotSoToxicPoisoN0o
Go to solution Solved by Techstorm970,
1 hour ago, o0NotSoToxicPoisoN0o said:

can you explain to me in English what this code is saying to java?

 

If the year is divisible by 4 and isn't divisible by 100, then it is a leap year.

 

However, if the year is divisible by 4 and is divisible by 400, then it is a leap year.

 

Otherwise, the year is not a leap year.

If so then I need help, I need to make a date validator for school.

What it should do:

1. Ask for Day, Month and Year.

2. Prints Valid for valid dates ie. 12/02/1995

3. Identify if a specific date is a leap year.

 

my problem is I dont know how to tell java to identify it a a leap year.

what equation to use and stuff...

Im using a compiler called BlueJ

Thanks in advance

Link to comment
Share on other sites

Link to post
Share on other sites

If year % 4 = 0 then leap year. I don't know java but I think that logic should work. 

 

 

Edit: disregard this, apparently my understanding of a leap year wasn't entirely accurate. 

******If you paste in text into your post, please click the "remove formatting" button for night theme users.******

CPU- Intel 6700k OC to 4.69 Ghz GPU- NVidia Geforce GTX 970 (MSI) RAM- 16gb DDR4 2400 SSD-2x500gb samsung 850 EVO(SATA) Raid 0 HDD- 2tb Seagate Case- H440 Red w/ custom lighting Motherboard - MSI Z170 Gaming A OS- Windows 10 Mouse- Razer Naga Epic Chroma, Final Mouse 2016 turney proKeyboard- Corsair k70 Cherry MX brown

Link to comment
Share on other sites

Link to post
Share on other sites

PC - CPU Ryzen 5 1600 - GPU Power Color Radeon 5700XT- Motherboard Gigabyte GA-AB350 Gaming - RAM 16GB Corsair Vengeance RGB - Storage 525GB Crucial MX300 SSD + 120GB Kingston SSD   PSU Corsair CX750M - Cooling Stock - Case White NZXT S340

 

Peripherals - Mouse Logitech G502 Wireless - Keyboard Logitech G915 TKL  Headset Razer Kraken Pro V2's - Displays 2x Acer 24" GF246(1080p, 75hz, Freesync) Steering Wheel & Pedals Logitech G29 & Shifter

 

         

Link to comment
Share on other sites

Link to post
Share on other sites

Just check the conditions in an if statement:

 

if (((year % 4 == 0) && (year % 100 != 0)) ||(year % 400 == 0)){

return true;

}

Link to comment
Share on other sites

Link to post
Share on other sites

Well, the definition of a leap year is kinda complicated.  Let's start there.

https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=leap+year+rules&*

Quote

There is a leap year every year whose number is perfectly divisible by four - except for years which are both divisible by 100 and not divisible by 400. The second part of the rule effects century years. For example; the century years 1600 and 2000 are leap years, but the century years 1700, 1800, and 1900 are not.

 

Sorry for the mess!  My laptop just went ROG!

"THE ROGUE":  ASUS ROG Zephyrus G15 GA503QR (2021)

  • Ryzen 9 5900HS
  • RTX 3070 Laptop GPU (80W)
  • 24GB DDR4-3200 (8+16)
  • 2TB SK Hynix NVMe (boot) + 2TB Crucial P2 NVMe (games)
  • 90Wh battery + 200W power brick
  • 15.6" 1440p 165Hz IPS Pantone display
  • Logitech G603 mouse + Logitech G733 headset

"Hex": Dell G7 7588 (2018)

  • i7-8750H
  • GTX 1060 Max-Q
  • 16GB DDR4-2666
  • 1TB SK Hynix NVMe (boot) + 2TB Crucial MX500 SATA (games)
  • 56Wh battery + 180W power brick
  • 15.6" 1080p 60Hz IPS display
  • Corsair Harpoon Wireless mouse + Corsair HS70 headset

"Mishiimin": Apple iMac 5K 27" (2017)

  • i7-7700K
  • Radeon Pro 580 8GB (basically a desktop R9 390)
  • 16GB DDR4-2400
  • 2TB SSHD
  • 400W power supply (I think?)
  • 27" 5K 75Hz Retina display
  • Logitech G213 keyboard + Logitech G203 Prodigy mouse

Other tech: Apple iPhone 14 Pro Max 256GB in White, Sennheiser PXC 550-II, Razer Hammerhead earbuds, JBL Tune Flex earbuds, OontZ Angle 3 Ultra, Raspberry Pi 400, Logitech M510 mouse, Redragon S113 keyboard & mouse, Cherry MX Silent Red keyboard, Cooler Master Devastator II keyboard (not in use), Sennheiser HD4.40BT (not in use)

Retired tech: Apple iPhone XR 256GB in Product(RED), Apple iPhone SE 64GB in Space Grey (2016), iPod Nano 7th Gen in Product(RED), Logitech G533 headset, Logitech G930 headset, Apple AirPods Gen 2 and Gen 3

Trash bin (do not buy): Logitech G935 headset, Logitech G933 headset, Cooler Master Devastator II mouse, Razer Atheris mouse, Chinese off-brand earbuds, anything made by Skullcandy

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, elpiop said:

if ((year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0)){

return true;

}

Uh...no.

 

if ((year % 4 == 0) && (year % 100 != 0))

{

return true;

}

else if ((year % 4 == 0) && (year % 400 == 0))

{

return true;

}

else

{

return false;

}

Sorry for the mess!  My laptop just went ROG!

"THE ROGUE":  ASUS ROG Zephyrus G15 GA503QR (2021)

  • Ryzen 9 5900HS
  • RTX 3070 Laptop GPU (80W)
  • 24GB DDR4-3200 (8+16)
  • 2TB SK Hynix NVMe (boot) + 2TB Crucial P2 NVMe (games)
  • 90Wh battery + 200W power brick
  • 15.6" 1440p 165Hz IPS Pantone display
  • Logitech G603 mouse + Logitech G733 headset

"Hex": Dell G7 7588 (2018)

  • i7-8750H
  • GTX 1060 Max-Q
  • 16GB DDR4-2666
  • 1TB SK Hynix NVMe (boot) + 2TB Crucial MX500 SATA (games)
  • 56Wh battery + 180W power brick
  • 15.6" 1080p 60Hz IPS display
  • Corsair Harpoon Wireless mouse + Corsair HS70 headset

"Mishiimin": Apple iMac 5K 27" (2017)

  • i7-7700K
  • Radeon Pro 580 8GB (basically a desktop R9 390)
  • 16GB DDR4-2400
  • 2TB SSHD
  • 400W power supply (I think?)
  • 27" 5K 75Hz Retina display
  • Logitech G213 keyboard + Logitech G203 Prodigy mouse

Other tech: Apple iPhone 14 Pro Max 256GB in White, Sennheiser PXC 550-II, Razer Hammerhead earbuds, JBL Tune Flex earbuds, OontZ Angle 3 Ultra, Raspberry Pi 400, Logitech M510 mouse, Redragon S113 keyboard & mouse, Cherry MX Silent Red keyboard, Cooler Master Devastator II keyboard (not in use), Sennheiser HD4.40BT (not in use)

Retired tech: Apple iPhone XR 256GB in Product(RED), Apple iPhone SE 64GB in Space Grey (2016), iPod Nano 7th Gen in Product(RED), Logitech G533 headset, Logitech G930 headset, Apple AirPods Gen 2 and Gen 3

Trash bin (do not buy): Logitech G935 headset, Logitech G933 headset, Cooler Master Devastator II mouse, Razer Atheris mouse, Chinese off-brand earbuds, anything made by Skullcandy

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, techstorm970 said:

Uh...no.

 

if ((year % 4 == 0) && (year % 100 != 0))

{

return true;

}

else if ((year % 4 == 0) && (year % 400 == 0))

{

return true;

}

else

{

return false;

}

yeah, my bad, i wrote that initially from memory. I edited my post after I checked and saw it was incorrect.

Link to comment
Share on other sites

Link to post
Share on other sites

On 24/03/2017 at 1:51 PM, techstorm970 said:

Uh...no.

 

if ((year % 4 == 0) && (year % 100 != 0))

{

return true;

}

else if ((year % 4 == 0) && (year % 400 == 0))

{

return true;

}

else

{

return false;

}

can you explain to me in English what this code is saying to java?

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, o0NotSoToxicPoisoN0o said:

can you explain to me in English what this code is saying to java?

 

If the year is divisible by 4 and isn't divisible by 100, then it is a leap year.

 

However, if the year is divisible by 4 and is divisible by 400, then it is a leap year.

 

Otherwise, the year is not a leap year.

Sorry for the mess!  My laptop just went ROG!

"THE ROGUE":  ASUS ROG Zephyrus G15 GA503QR (2021)

  • Ryzen 9 5900HS
  • RTX 3070 Laptop GPU (80W)
  • 24GB DDR4-3200 (8+16)
  • 2TB SK Hynix NVMe (boot) + 2TB Crucial P2 NVMe (games)
  • 90Wh battery + 200W power brick
  • 15.6" 1440p 165Hz IPS Pantone display
  • Logitech G603 mouse + Logitech G733 headset

"Hex": Dell G7 7588 (2018)

  • i7-8750H
  • GTX 1060 Max-Q
  • 16GB DDR4-2666
  • 1TB SK Hynix NVMe (boot) + 2TB Crucial MX500 SATA (games)
  • 56Wh battery + 180W power brick
  • 15.6" 1080p 60Hz IPS display
  • Corsair Harpoon Wireless mouse + Corsair HS70 headset

"Mishiimin": Apple iMac 5K 27" (2017)

  • i7-7700K
  • Radeon Pro 580 8GB (basically a desktop R9 390)
  • 16GB DDR4-2400
  • 2TB SSHD
  • 400W power supply (I think?)
  • 27" 5K 75Hz Retina display
  • Logitech G213 keyboard + Logitech G203 Prodigy mouse

Other tech: Apple iPhone 14 Pro Max 256GB in White, Sennheiser PXC 550-II, Razer Hammerhead earbuds, JBL Tune Flex earbuds, OontZ Angle 3 Ultra, Raspberry Pi 400, Logitech M510 mouse, Redragon S113 keyboard & mouse, Cherry MX Silent Red keyboard, Cooler Master Devastator II keyboard (not in use), Sennheiser HD4.40BT (not in use)

Retired tech: Apple iPhone XR 256GB in Product(RED), Apple iPhone SE 64GB in Space Grey (2016), iPod Nano 7th Gen in Product(RED), Logitech G533 headset, Logitech G930 headset, Apple AirPods Gen 2 and Gen 3

Trash bin (do not buy): Logitech G935 headset, Logitech G933 headset, Cooler Master Devastator II mouse, Razer Atheris mouse, Chinese off-brand earbuds, anything made by Skullcandy

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×