Answer to Question #214667 in Java | JSP | JSF for Fdfd

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.
1
Expert's answer
2021-07-07T06:15:08-0400
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]));
		    
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS