מספרים אקראיים
int fromNum,toNum,range;
fromNum = -16;
toNum = -5;
range = toNum – fromNum + 1;
int num = (int)(Math.random()*range) + fromNum;
for (int i=0;i<10;i++) {
System.out.println(num);
num = (int)(Math.random()*range) + fromNum;
}
שאלת הטרפז
int n;
System.out.println("Please insert the base");
n = reader.nextInt();
int h = n / 3;
for (int row=0;row<h;row++) {
for (int j=0;j<row;j++) {
System.out.print(" ");
}
for (int j=0;j<n–row*2;j++){
System.out.print("*");
}
System.out.println();
}
/*
(0)********** n
(1) ******** n-2
(2) ****** n-4
(3) **** n-6
*/