Created
April 26, 2012 14:10
-
-
Save ngnguyen1/2499874 to your computer and use it in GitHub Desktop.
Day So
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*+--------------------------+ | |
| Java Programing Language.| | |
| Author: nduy.nga. | | |
| ThaiNguyen University. | | |
+--------------------------+*/ | |
package DS; | |
import java.util.Scanner; | |
public class DaySo | |
{ | |
private int n; | |
private int m[]; | |
static Scanner input=new Scanner(System.in); | |
public DaySo() | |
{} | |
public DaySo(int spt) | |
{ | |
this.n=spt; | |
} | |
public DaySo(int m1[]) | |
{ | |
this.m=m1; | |
} | |
public void nhapDS() | |
{ | |
System.out.print("Nhap vao so phan tu cua mang: "); | |
n = input.nextInt(); | |
m=new int[n]; | |
for (int i=0;i<n ;i++ ) | |
{ | |
System.out.print("m[" +i+"]= "); | |
m[i]=input.nextInt(); | |
} | |
} | |
public void inDS(String y) | |
{ | |
System.out.print(y); | |
for (int i=0;i<n ;i++ ) | |
{ | |
System.out.print(this.m[i]+" "); | |
} | |
System.out.println(); | |
} | |
public DaySo congDS(DaySo ds) | |
{ | |
DaySo dsTong=new DaySo(); | |
dsTong.m=new int[n]; | |
for (int i=0;i<n ;i++) | |
{ | |
dsTong.m[i]=this.m[i]+ds.m[i]; | |
} | |
return dsTong; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*+--------------------------+ | |
| Java Programing Language.| | |
| Author: nduy.nga. | | |
| ThaiNguyen University. | | |
+--------------------------+*/ | |
import DS.*; | |
import java.util.Scanner; | |
public class TestDS | |
{ | |
Scanner input=new Scanner(System.in); | |
public static void main(String[] argv) | |
{ | |
DaySo ds=new DaySo(); | |
DaySo ds1=new DaySo(); | |
ds.nhapDS(); | |
ds.inDS("Day So 1 nhap la: "); | |
ds1.nhapDS(); | |
ds1.inDS("day so 2 vua nhap la: "); | |
ds.congDS(ds1).inDS("Tong 2 day so la: "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment