Question #214667

Write a program that prompts the user to enter five integers that you store in an array. Write a function called quadruple() that takes a single-integer parameter and multiplies it by 4, returning the result to the calling program. Call the function once for each of the five integers, then display the quadrupled results from within the main() function.

Expert's answer

import java.util.Scanner;


public class Main
{
    public static int quadruple(int n){
        return (n*4);
    }
	public static void main(String[] args) {
		System.out.println("Enter five integers: ");
		int arr[]=new int[5];
		Scanner in=new Scanner(System.in);
		for(int i=0;i<5;i++){
		    arr[i]=in.nextInt();
		    
		}
		
		for(int i=0;i<5;i++){
		    System.out.println("Quadruple of "+arr[i]+" is "+quadruple(arr[i]));
		    
		}
	}
}

LATEST TUTORIALS
APPROVED BY CLIENTS