Count the number of notes

Asked

Viewed 113 times

0

The program needs to enter the value of notes. When typing, the program must return number of notes 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;
    }
}
  • 3

    And what is your doubt?

  • how to return the number of notes

1 answer

0

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

Example:

System.out.println(numeroDeNotas.length);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.