Question

In java please :-)12 values have been input into array yearlyValues. Output all 12 elements, with 4 per line. If the elements are 10 20 30 40 5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Give me a thumbs up if you like my work !!!

I have written the below Java Program based on your requirements.

Just Save the below code as Main.java and then Compile & Run the code. It will work smoothly.

The below code has no-error and it is working perfectly.

I have also attached the Output Screenshot that I got by running the below program.

Output:

4. Command Prompt C:\Users\Public>javac Main.java C:\Users\Public>java Main 10 20 30 40 50 60 70 80 90 100 110 120 10 20 30 4

*******************************************************************************************************************

Code:

Main.java

import java.io.*;
import java.util.*;

public class Main
{
   public static void main(String[] args)
   {
       Scanner sc=new Scanner(System.in);
      
       int yearlyValues[]=new int[12];
      
       for(int i=0;i<12;i++)
       {
           yearlyValues[i]=sc.nextInt();
       }
      
       for(int i=0;i<12;i+=4)
       {
System.out.print(yearlyValues[i]+" ");
           System.out.print(yearlyValues[i+1]+" ");
           System.out.print(yearlyValues[i+2]+" ");
           System.out.print(yearlyValues[i+3]);
          
           System.out.println();
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
In java please :-) 12 values have been input into array yearlyValues. Output all 12 elements,...
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
ADVERTISEMENT