In: Computer Science
In each part below, a task is described. Your job is to write one or more JAVA statements which will accomplish this task. Assume that all variables have data type int. If you need other variables you may declare them and use them.
a. 6 pts Assume that variables x, y, and z have values. Print all the values from x to y that are evenly divisible by z. For example, if x is 6, y is 18, and z is 4, it would print 8 12 16
b. 6 pts. Given a year number, year, calculate and print how many centuries (100 years), decades (10 years), and years have passed since 0 CE. For example, for year = 2021, you would print “Year 2021: 20 centuries, 2 decade(s), 1 year(s)”.
// Part A int x = 6, y = 18, z = 4; for (int num = x; num <= y; num++) { if (num % z == 0) System.out.print(num + " "); }
==========================================================
// Part B int year = 2021; int centuries = year / 100; int decades = (year % 100) / 10; int years = year % 10; System.out.println("Year " + year + ": " + centuries + " centuries, " + decades + " decade(s), " + years + " year(s).");
===============================================================