/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ktlt10;
import java.util.*;
/**
*
* @author HuongUD
*/
public class Cau10 {
public static void main(String[] args) {
int a[] = null, n = 0, chon = 0;
Cau10 ds = new Cau10();
while(chon != 4){
System.out.println("------------------------------");
System.out.println("Chon 1 de Nhap day so");
System.out.println("Chon 2 de Tim phan tu lon nhat");
System.out.println("Chon 3 de Tinh tong day");
System.out.println("Chon 4 de Ket thuc");
System.out.println("------------------------------");
System.out.print("Chon: ");
Scanner input = new Scanner (System.in);
chon = input.nextInt();
switch (chon) {
case 1:
ds.nhap(a);
break;
case 2:
ds.timMax(a, n);
System.out.println("Phan tu lon nhat la: " + timMax(a, n));
break;
case 3:
ds.tinhTong(a, n);
System.out.println("Tong cua day la: " + tinhTong(a, n));
break;
case 4:
quit();
default:
System.out.println("Ban da nhap sai moi ban nhap lai!");
}
}
}
public static void nhap(int a[]){
System.out.print("Nhap so phan tu day: ");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
a = new int[n];
for (int i = 0; i < a.length; i++) {
System.out.print("a[" + i + "]: ");
a[i] = input.nextInt();
}
}
public static int timMax(int a[], int n){
if(n == 1)
return a[0];
else{
if(a[n - 1] > timMax(a, n - 1))
return a[n - 1];
else
return timMax(a, n- 1);
}
}
public static int tinhTong(int a[], int n){
if(n == 1)
return a[0];
else
return a[n - 1] + tinhTong(a, n - 1);
}
public static void quit(){
System.exit(0);
}
}
Mình mới học về java nên ko thành thạo về nó mong mn thông cảm. Chương trình mình viết ra vậy nhưng không chạy, ai giúp mình sửa lỗi với. Cảm ơn mn ạ!


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?