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
7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added employee.dat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
40 changes: 39 additions & 1 deletion src/nestech/javacourse/example/baitap/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,44 @@
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// implement your code here
boolean isRunning = true;

while(isRunning){
System.out.println("1. Summation (+) ");
System.out.println("2. Subtraction (-) ");
System.out.println("3. Multiplication (*)");
System.out.println("4. Division (/) ");
System.out.println("0. Exit");
int choice = scanner.nextInt();

if(choice != 0){
System.out.println("Enter first number: ");
double firstNumber = scanner.nextDouble();
System.out.println("Enter second number: ");
double secondNumber = scanner.nextDouble();

switch (choice){
case 1:
System.out.println(firstNumber + secondNumber);
break;
case 2:
System.out.println(firstNumber - secondNumber);
break;
case 3:
System.out.println(firstNumber * secondNumber);
break;
case 4:
System.out.println(firstNumber / secondNumber);
break;
default:
System.out.println("The choice is invalid please enter again");
}

}
else {
System.out.println("Closing application...");
isRunning = false;
}
}
}
}
13 changes: 11 additions & 2 deletions src/nestech/javacourse/example/baitap/PrimeChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ public static void main(String[] args) {

public static boolean isPrime(int n) {
boolean isValid = false;
// Implement your code here

if (n > 2){
for(int i = 2; i < Math.sqrt(n); i++){
if(n % i != 0){
isValid = true;
break;
}
else {
isValid = false;
}
}
}
return isValid;
}
}
15 changes: 14 additions & 1 deletion src/nestech/javacourse/example/baitap/SecondLargestNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ public static void main(String[] args) {

public static int findSecondLargest(int[] arr) {
int secondLargest = Integer.MIN_VALUE;
// Implement your code here
int largest = Integer.MIN_VALUE; // đảm bảo các giá trị của số nguyên trong mảng sẽ lớn hơn giá trị ban đầu

if(arr.length < 2){
return Integer.MIN_VALUE;
}

for (int num : arr){
if(num > largest){
secondLargest = largest;
largest = num;
}else if(num > secondLargest && num != largest){
secondLargest = num;
}
}

return secondLargest;
}
Expand Down
20 changes: 20 additions & 0 deletions src/nestech/javacourse/example/baitap/StudentManagement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package nestech.javacourse.example.baitap;


import nestech.javacourse.example.condition.Student;

public class StudentManagement {
public static void main(String[] args) {
Student[] stdArray = new Student[3];

stdArray[0] = new Student(1,"Nguyen","Le",9);
stdArray[1] = new Student(1,"Hieu","Nguyen",8);
stdArray[2] = new Student(1,"Ly","Pham",10);

for(Student score : stdArray){
if(score.getScore() > 5){
System.out.println(score.getFirstName());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ public static void main(String[] args) {

public static int calculateCommonElementsSum(int[] arr1, int[] arr2) {
int sum = 0;
// Implement your code here
for(int i = 0; i < arr1.length; i++){
for( int j = 0; j < arr2.length; j++){
if(arr1[i] == arr2[j]){
sum += arr1[i] + arr2[j];
break;
}
}
}
return sum;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package nestech.javacourse.example.baitap.exerciseswithfiles;

import java.io.Serializable;

public class Employee implements Serializable {

private long id;
private String name;
private int age;
private String position;

public Employee(long id, String name, int age, String position) {
this.id = id;
this.name = name;
this.age = age;
this.position = position;
}

@Override
public String toString() {
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
", age='" + age + '\'' +
", position='" + position + '\'' +
'}';
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getPosition() {
return position;
}

public void setPosition(String position) {
this.position = position;
}
}
Loading