我有一个函数可以在ng-repeat中返回一个值。它基本上为ng-repeat的每个对象创建一个总数。
如何将每个返回值推送到新数组?我尝试过以下方法:
$scope.lineTotal = function(line){
var markup = 1 + (line.markupPct / 100);
var discount = 1 - (line.discountPct / 100);
var lineTotal = line.price * discount * markup * line.qty;
return lineTotal;
$scope.newArray.push(lineTotal);
}
答案 0 :(得分:0)
public class Main {
public static void main(String[] args) {
// write your code here
int size = 8;
int[][] matrix = new int[size][size];
for (int i = 0; i < size ; i++) {
for (int j = 0; j < size; j++) {
matrix[i][j] = (i+(2*j));
}
}
trace(matrix, size);
rotate(matrix);
System.out.println("________________________");
trace(matrix, size);
}
public static void rotate(int[][] matrix){
int stop = matrix.length -1;
rotate(matrix, stop, 0);
}
public static void rotate(int[][] matrix, int stop, int start){
if(start - stop == 1) return;
int [] temp = new int[stop-start];
//save top row in an array
for (int i = 0; i < stop-start ; i++) {
temp[i] = matrix[start][start+i+1];
}
//System.out.println(Arrays.toString(temp));
//left goes to top
for (int i = start; i < stop ; i++) {
matrix[start][start+stop-i] = matrix[i][start];
}
//bottom goes to left
for (int i = start; i < stop ; i++) {
matrix[i][start] = matrix[stop][i];
}
//right goes to bottom
for (int i = start; i < stop ; i++) {
matrix[stop][i] = matrix[start+stop-i][stop];
}
//temp array goes to right
for (int i = 0; i < temp.length ; i++) {
matrix[start + i + 1][stop] = temp[i];
}
rotate(matrix, stop-1, start + 1);
}
public static void trace(int[][] matrix, int size){
for (int i = 0; i < size; i++) {
for (int j = 0; j < size ; j++) {
System.out.printf("%2d ", matrix[i][j]);
}
System.out.println();
}
}