POO tp_codecheck finished

This commit is contained in:
TiagoRG 2023-02-20 13:45:49 +00:00
parent f3aed8ea20
commit 67a6588745
6 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,23 @@
# Exercícios de Arrays
## Ex1
```java
final int LENGHT = 100;
int[] a = new int[LENGHT];
// Code for filling a ommited
for (int = 99; i >= 0; i--)
{
System.out.print(a[i]);
if (i > 0) { System.out.print(', '); }
}
```
## Ex2
```java
int[] numbers = new int[100];
for (int k = 0; k < numbers.length; k++)
{
numbers[k] = k + 1;
}
```

View File

@ -0,0 +1,23 @@
# Exercícios de Arrays
## Ex1
```java
final int LENGHT = 100;
int[] a = new int[LENGHT];
// Code for filling a ommited
for (int = 99; i >= 0; i--)
{
System.out.print(a[i]);
if (i > 0) { System.out.print(', '); }
}
```
## Ex2
```java
int[] numbers = new int[100];
for (int k = 0; k < numbers.length; k++)
{
numbers[k] = k + 1;
}
```

View File

@ -0,0 +1,27 @@
package tp_codecheck.tp02;
import java.util.Scanner;
public class NumberOfDays {
public static void main(String[] args)
{
// Declare and initialize daysOfMonth
int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Scanner in = new Scanner(System.in);
System.out.print("Month (1 - 12): ");
int month = in.nextInt();
System.out.print("Year: ");
int year = in.nextInt();
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
// It's a leap year. Adjust the entry for February
daysOfMonth[1]+=1;
}
// Get the number of days in the given month
int days = daysOfMonth[month-1];
System.out.println("Number of days: " + days);
}
}

View File

@ -0,0 +1,17 @@
package tp_codecheck.tp02;
public class Numbers {
public static void main(String[] args) {
// Different arrays will be substituted here.
int[] values = { 3, 1, 4, 1, 5, 9 };
int[] newValues = new int[values.length/2];
for (int x = 0; x < values.length; x+=2) {
newValues[x/2] = values[x];
}
for (int i = 0; i < newValues.length; i++) {
System.out.println(newValues[i]);
}
}
}