تمرین 1: یک پاراگراف درباره unicode
تمرین 2:برنامه ای بنویسید که یک اسم را بگیرد و در فایلی به همان نام 5 بار بنویسد
Donald Knuth: (…) computer programming is an art, because it applies accumulated knowledge to the world, because it requires skill and ingenuity, and especially because it produces objects of beauty. A programmer who subconsciously views himself as an artist will enjoy what he does and will do it better.
DS.java:
import java.util.HashMap;
import java.util.HashSet;
import java.util.Vector;
public class DS {
public static void main(String[] args) {
int[] a;
a = new int[4];
a[0]=2;
a[1]=3;
a[2]=4;
a[3]=8;
//a[4]=9; ArrayIndexOutOBE
for (int i=0; iSystem.out.println(a[i]);
}
for (int i:a){
System.out.println(i);
}
Vectorv = new Vector ();
v.add(1);
v.add(2);
v.add(5);
for (int i=0; iSystem.out.println(v.get(i));
}
for (int x:v){
System.out.println(x);
}
//removing an element from vector
v.remove(2);
v.add(2, 89);
//-------------- HashMap ---------------------------
HashMapgrades;
grades = new HashMap();
grades.put("azin", 10);
grades.put("asghar",5);
System.out.println(grades.get("azin"));
for (String name:grades.keySet()){
System.out.println(grades.get(name));
}
HashMap, HashMap >>> c;
c = new HashMap,HashMap >>>();
//-----------------------
HashSets=new HashSet ();
s.add(3);
s.add(6);
s.add(3);
for (int x:s){
System.out.println(x);
}
}
}
public class Student{
int stdid;
String name;
private int x=3;
public Student(int stdid, String name){
this.stdid = stdid;
this.name = name;
}
public String toString(){
return name + ": " + stdid;
}
public static void main(String args[]){
Student x = new Student(123, "azin");
System.out.println(x);
University u = new University();
u.addStudent(x);
u.addStudent(x);
u.addStudent(x);
u.print();
}
// public void setX(int x) {
// this.x = x;
// }
public int getX() {
return x;
}
}
University.java:
import java.util.Vector;
public class University{
Vector
public void addStudent(Student s){
students.add(s);
}
public void print(){
//foreach
for (Student s: students){
System.out.println(s);
System.out.println(s.getX());
}
}
}