Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

81 changes: 81 additions & 0 deletions Java/1.10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// EX 1.10 Write a program to get next day of a given date
// Write a program to get next day of a given date.

// Please don't use any library of Java.

// Test data 1
// Input: 2020, 02, 29
// Output: 2020, 03, 01
import java.util.Scanner;
public class Main {
public static void main(String[] Strings) {
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
var year = string.substring(0,4);
int nam = Integer.parseInt(year);
var month = string.substring(6,8);
int thang = Integer.parseInt(month);
var day = string.substring(10,12);
int ngay = Integer.parseInt(day);
boolean nhuan = true;
int i;
if (nam % 400 == 0) {
nhuan = true;
}
else if (nam % 100 == 0) {
nhuan = false;
}
else if (nam % 4 == 0) {
nhuan = true;
}
else {
nhuan = false;
}

if (thang == 1 || thang == 3 || thang == 5 || thang == 7 || thang == 8 || thang == 10 || thang == 12) {
i = 31;
}
else if (thang == 2) {
if (nhuan) {
i = 29;
}
else {
i = 28;
}
}
else {
i = 30;
}

if (ngay < i) {
ngay = ngay + 1;
}
else {
ngay = 1;
if (thang == 12) {
thang = 1;
nam = nam + 1;
}
else {
thang = thang + 1;
}
}
System.out.print(nam);
System.out.print(", ");
if (thang < 10) {
System.out.print("0");
System.out.print(thang);
}
else {
System.out.print(thang);
}
System.out.print(", ");
if (ngay < 10) {
System.out.print("0");
System.out.print(ngay);
}
else {
System.out.print(ngay);
}
}
}
26 changes: 26 additions & 0 deletions Java/1.2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// EX 1.2 Write a program that takes a year from the user and print whether that year is a leap year or not.
// Write a program that takes a year from the user and print whether that year is a leap year or not.
// Test Data

// Input the year: 2016

// Expected Output : True
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
int year = scanner.nextInt();
if ( year % 4 == 0 && year % 100 != 0) {
System.out.print("True");
}
else if ( year % 400 == 0) {
System.out.print("True");
}
else {
System.out.print("False");
}
}
}
}
File renamed without changes.
65 changes: 65 additions & 0 deletions Java/1.4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// EX 1.4. Write a program which reads a sequence of integers and prints how often each number of this sequence occurs.
// Write a program which reads a sequence of integers and prints how often each number of this sequence occurs.

// Example

// Input:

// 9

// 1 3 5 7 5 3 7 2 5

// Output:

// 1(1), 3(2), 5(3), 7(2), 2(1)



// Please note that:

// 9 as array size

// 1 3 5 7 5 3 7 2 5 as array
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int[] arr = new int[a];
for (int i = 0; i < a; i++) {
arr[i] = scanner.nextInt();
}

boolean check = true;
boolean first = true;
for (int i = 0; i < arr.length; i++) {
check = true;
for (int j = 0; j < i; j++) {
if (arr[i] == arr[j]) {
check = false;
break;
}
}

if (check == true) {
int sum = 1;
for (int j = i + 1; j < arr.length; j++) {
if (arr[j] == arr[i]) {
sum++;
}
}
if (first == true) {
System.out.print(arr[i] + "(" + sum + ")");
first = false;
} else {
System.out.print(", " + arr[i] + "(" + sum + ")");
}

}
}

}
}

41 changes: 41 additions & 0 deletions Java/1.5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// EX 1.5. Write a program that accept an integer (n) from the user and outputs combinations that express n as a sum of two prime numbers.
// Write a program that accept an integer (n) from the user and outputs combinations that express n as a sum of two prime numbers.

// Example

// Input: 10

// Output: 7+3, 5+5
import java.util.Scanner;

public class Main {
private static boolean isPrime(int a) {
if ( a < 2) {
return false;
}
for ( int i = 2; i < a; i++) {
if ( a % i == 0) {
return false;
}
}
return true;
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
boolean first = true;
for (int i = a -2; i >= a /2; i--) {
if ( isPrime(i) && isPrime(a-i)) {
if ( first == true) {
first = false;
System.out.print( i + "+" + (a - i));
}
else {
System.out.print( ", " + i + "+" + (a - i));
}
}
}
}
}

44 changes: 44 additions & 0 deletions Java/1.6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// EX 1.6 Write a program to check whether the sequence of numbers 1, 2, 3 appears in a given array of integers somewhere.
// Write a program to check whether the sequence of numbers 1, 2, 3 appears in a given array of integers somewhere.

// Example
// Input:
// 5
// 1 1 2 3 1
// Output: 1
// Please note that:
// 5 as array size
// 1 1 2 3 1 as array

import java.util.Scanner;

/**
* array2
*/
public class Main {
public static boolean test(int[] a) {
for (int i = 0; i < a.length-2 ; i++) {
if (a[i] == 1 && a[i + 1] == 2 && a[i + i] == 3) {
return true;
}
}
return false;
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
if (test(a)) {
System.out.print(0);
} else {
System.out.print(1);
}
}
}



56 changes: 56 additions & 0 deletions Java/1.7.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// EX 1.7 If a number appears three times in a row in an array it is called a triple. Write a program to check if a triple is presents in an array of integers or not.
// If a value appears three times in a row in an array it is called a triple. Write a program to check if a triple is presents in an array of integers or not.

// Example
// Input:
// 7
// 1 1 1 2 2 2 1
// Output:
// 1

// Please note that:

// 7 as array size
// 1 1 1 2 2 2 1 as array
import java.util.Scanner;

/**
* array2
*/
public class Main{
public static boolean test(int[] a, int n) {
for (int i = 0; i < n-1; i++) {
if (a[i] == a[i + 1] && a[i] == a[i + 2] && a[i + 1] == a[i + 2]) {
{
return true;
}
}
}
return false;

}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}

if (test(a, n) == true) {
System.out.print(1);
} else {
System.out.print(0);
}
// for (int i = 0; i < a.length; i++) {
// System.out.print(a[i] + " ");
// }
}
}







Loading