Question

Write a program where you hardcode 4 numerical values for an array. Write a loop to...

Write a program where you hardcode 4 numerical values for an array. Write a loop to print those values. Another loop to multiply those values by some constant and store them in the original array variable. Print the array values again. ***in Java

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class TestCode {
    public static void main(String[] args) {
        int arr[] = {4,2,3,5};

        for(int i = 0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();

        for(int i = 0;i<arr.length;i++){
            arr[i] = arr[i]*9;
        }

        for(int i = 0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
}

4 2 3 5 
36 18 27 45 

Add a comment
Know the answer?
Add Answer to:
Write a program where you hardcode 4 numerical values for an array. Write a loop to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT