Count the number of notes

0

The program needs to enter the note value. When typing, the program should return number of notes of 20,10,5 1

/* Code in Java */
import java.util.Scanner;

class HelloWorld {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n;
        int notas[] = {20, 10, 5, 1};
        int numeroNotas[]={0,0,0,0};
        int i;
        System.out.println("Digite o numero:");
        n = sc.nextInt();

        while(n!=0){
            System.out.println("Digite o numero:");
            n = sc.nextInt();
        }

        for(i=0;i<=notas.length-1;i++){
            System.out.println(" notas de "+notas[i]+" ="+numeroNotas[i]);
        }
    }
    private static int conversor(int []notas,int n, int numeroNotas[]){

        int i=0;

        while(n%notas[i]==0){        
            i++;
        }
        numeroNotas[i]=numeroNotas[i]+1;

        return i;
    }
}
    
asked by anonymous 27.08.2016 / 21:24

1 answer

0

To display the number of objects in the array (which in this case is the number of notes), you use the length.

Example:

System.out.println (NumberNotes.length);

    
29.08.2016 / 18:14