how to print a new line after a certain number of prints

how to print a new line after a certain number of prints

How do I make this program print the inputs the user gives 5 per line? So in other words I want the program to print 5 input numbers per line. this is my code so far...import java.util.Scanner; public class AnyAverageArr {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner anyaverage = new Scanner(System.in);

    System.out.println("This program will find the average of any numbers");
    System.out.print("Please choose amount of numbers to average ");
    int max = anyaverage.nextInt();

    int [] Arr1 = new int[max];

    int i;
    for (i=0; i<max; i++)
    do {
        System.out.print("Please enter " + i + " number: ");
        Arr1[i]= anyaverage.nextInt();
        i++;
    }
        while (i<max);



    System.out.println("The numbers being averaged: ");
        for (i=0;i<max; i++)
            {System.out.print(Arr1[i] + " ");
            if (i%5==0) 
                System.out.println();
            }










}

}

View Answers

November 15, 2010 at 11:41 AM

Hi Friend,

Here is your required code:

import java.util.*;
class AnyAverageArr{
    public static void main(String[] args){
    int counter=0,sum=0;
    Scanner anyaverage = new Scanner(System.in);

    System.out.println("This program will find the average of any numbers");
    System.out.print("Please choose amount of numbers to average ");
    int max = anyaverage.nextInt();
    String output="";
    int [] Arr1 = new int[max];

    int i;
    for (i=0; i<max; i++)
    do {
        System.out.print("Please enter " + i + " number: ");
        Arr1[i]= anyaverage.nextInt();

        i++;
    }
        while (i<max);
    System.out.println("The numbers being averaged: ");
        for (i=0;i<max; i++){
            sum+= Arr1[i];
            output += " " +Arr1[i];
            counter++;
            if (counter==5) {
                output += "\n";
                counter=0;
            }
            }
            System.out.println(output);
            System.out.println("Average of Numbers: ");
            int avg=sum/max;
            System.out.println(avg);
    }
}

Thanks









Related Tutorials/Questions & Answers:
how to print a new line after a certain number of prints
how to print a new line after a certain number of prints  How do I make this program print the inputs the user gives 5 per line? So in other words I want the program to print 5 input numbers per line. this is my code so far
How to insert new line after every space in java
How to insert new line after every space in java  Hii Sir, I have a string with values 69 17 17 16 2 1 1 26 26 56 like this .Now as per my need i have to put all these values into new lines on getting space
Advertisements
How to write file text In New Line
How to write file text In New Line  Hi friends, How to write file text in new line in Java program. How to write the syntax for this with example... text in a new line. For finds examples or syntax please visit the link How
print square of any number
print square of any number  using c++ language, write aprogram to print the square of any number entered by the user
python print on same line in loop
the print() method it is printing new data in next line. So, I want to avoid this and print in the same line. Let's know how to make function in Python to print data...python print on same line in loop  Hi, I have a unique requirement
Clear the print button after onclicking the print - Ajax
Clear the print button after onclicking the print  var disp_setting... correct answer.... pls clear the print and ok button when after onclicking...=yes,width=700, height=330,left=300,top=325"; var rate_print=window.open
Updating variables in a loop? and only printing certain messages after the first iteration?!
Updating variables in a loop? and only printing certain messages after the first iteration?!  I've written a program that reads two values. I... computed data. But I'm really confused on how I would go about this, such as how
ModuleNotFoundError: No module named 'number-line'
'number-line' How to remove the ModuleNotFoundError: No module named '... with following command: pip install number-line After the installation...ModuleNotFoundError: No module named 'number-line'  Hi, My Python
print the sum of even number from 1 to 100
print the sum of even number from 1 to 100  how to print the sum of even number from 1 to 100 using for loops? Thanks
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
); System.out.println("\nReverse the number"+i); S.out(); } }   print...Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c  class rose { int n
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want... down will be in a new line how can i do this i m showing my codes here please... { xmlHttp=new XMLHttpRequest
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want... down will be in a new line how can i do this i m showing my codes here please... { xmlHttp=new
Java file new line
Java file new line In this section, you will learn how to write the text in new line of text file. Description of code: The package java.io.* has provide...() writes a line separator and allow to write next text to another line in 
line number in a file of entered string
line number in a file of entered string  when i entered string from console , it should show line number in a file of that string
Clear the print button after onclicking the print - JSP-Servlet
Clear the print button after onclicking the print  rate_print.document.writeln(" "); hai sir, this is my java script code, i ask how to clear the printbutton image when after onclicking the print button....  Hi
Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any given number. Prime Number is a number that is not divisible by any number other..., which automatically prints Prime Number starting from 1 to 50. Example
ModuleNotFoundError: No module named 'nose-run-line-number'
: No module named 'nose-run-line-number' How to remove the ModuleNotFoundError...-line-number After the installation of nose-run-line-number python library...ModuleNotFoundError: No module named 'nose-run-line-number'  Hi
Write Text To File In New Line.
Write Text To File In New Line. In this tutorial you will learn how to write text into file in a new line. When you are writing in a file you may be required to finish the line and want to write the other text in a new line
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
Count number of occurences and print names alphabetically in Java
Count number of occurences and print names alphabetically in Java  I... for the printCount() method for the code to count the number of occurences of each word and print in alphabetical order to produce this output: {bob=1, jim=1, tim=1
How to print this in java?
How to print pattern in Java?  How to print a particular pattern... and click the button that consists of binary number 0 and 1 from the text editor.    How to print this in java
how to print dot in python without newline
to print 20 dots without new line. Is there any easy solution? how to print dot... without new line. Here is output of the program. >>> print("."*10...how to print dot in python without newline  Hi, I a debugging
how to print dot in python without newline
places i want to print 20 dots without new line. Is there any easy solution...("."*10);ADS_TO_REPLACE_4 This code will print 10 dots without new line...how to print dot in python without newline  Hi, I a debugging
ModuleNotFoundError: No module named 'prints'
'prints' How to remove the ModuleNotFoundError: No module named 'prints'...: pip install prints After the installation of prints python library...ModuleNotFoundError: No module named 'prints'  Hi, My Python
How to design a foot print on the sand, print on the sand, print
How to design a foot print on the sand       You might have seen foot prints on the sand field. Do you think, it can be design in the photoshop, yes I have done here. I have used
while Append need a new line for column and row
while Append need a new line for column and row  HI While using append in javascript for retreiving the rows and its column header, its retreiving but after column header i need new line but it is not coming. Thanks in advance
how to print the server time
how to print the server time  how to print the server time in jsp and update time in fix interval
How to print this Format exactly?
How to print this Format exactly?   * * * & reverse
how to print - Java Beginners
how to print  how to print something on console without using... anything on the console. import java.io.*; public class Print{ public static void main(String args[]) { PrintWriter pw = new PrintWriter(System.out, true
Java number calculation using while loop
Java number calculation using while loop In this tutorial, you will learn how to use while loop to solve certain number calculations. Here is an example...){ int sum=0,sumSquares=0; int num1=0,num2=0; Scanner input=new Scanner(System.in
how to print the server time
how to print the server time  i want to print database time in clintside and update time in every secound without creating connection to database for each time. how can i do
how to print String as pattern ?
how to print String as pattern ?  i have a one String name ="rajesh" i want to print pattern like r * ra ** raj raje rajes rajesh please help me
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
How to format number in Java?
How to format number in Java?  Hi, What is the best way to format a number in Java? How to format number in Java? Thanks   Hi... number after decimal places numberFormat.setMinimumFractionDigits(3
How to Print a Stack Trace Message
How to Print a Stack Trace Message  Debugging of Java program requires... times you have to print the detailed error message on the console... will print the detailed message on the console. You can use
Line Number Reader Example
Line Number Reader Example      ... class is provide getLineNumber() method to get the number of line. We...: getLineNumber(): This method is used to get the number of line. readLine
how to print the following pattern
how to print the following pattern  Hello hEllo heLlo helLo hellO pls reply soon its an emergency   class StringPattern { public..."; StringBuffer buffer=new StringBuffer(st); for(int i=0;i<st.length();i
Limiting the Values in a Number JSpinner Component
will learn how to create a Number JSpinner that can take values up to certain maximum... Limiting the Values in a Number JSpinner Component... up to certain maximum limit. Following program has used some methods and APIs
How to print list of files in client system
How to print list of files in client system  have some list of files in server.i just want to print that files in client machine with out opening the file.i give the option for user like printall.if user click printall prints
how to print pdf format
how to print pdf format  Hi every body iam doing school project iam using backend as oracle front end java .how to print student marks list...*"%> <% Document document=new Document(); PdfWriter.getInstance(document
how to print spark dataframe data
how to print spark dataframe data  Hi, I have a dataframe in spark and i want to print all the data on console. How it can be done. how to print... is in "data" variable and you want to print it. Its simple and one line function to print
how to print spark dataframe data
how to print spark dataframe data  Hi, I have a dataframe in spark and i want to print all the data on console. How it can be done. how to print... is in "data" variable and you want to print it. Its simple and one line function to print
How to print UIButton id
How to print UIButton id  How to get the id of the button in the IOS application? Thanks   Hi, You can use the following code: - (IBAction)btnClicked:(id)sender { UIButton *button = (UIButton *)sender; int
print without newline in python
in which it prints strings. But the output is coming in new line. But I want the print it in one line. My example: print("I ") print("Love ") print("Python") But the output is coming in new lines. I want to know how to print without
print without newline in python
in which it prints strings. But the output is coming in new line. But I want the print it in one line. My example:ADS_TO_REPLACE_1 print("I ") print("Love ") print("Python") But the output is coming in new lines. I want to know how
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line In this tutorial I will explain you how you can read big file line by line... legacy data and add it to your new database system. Example discussed here
How to print like printf in python
How to print like printf in python  Hi, I am from C background and there used to be printf function. Jow to print like printf in python? The printf function is C/C++ is very useful. So, looking for some line printf in Python
How To Read String From Command Line In Java
How To Read String From Command Line In Java In this section we will discuss about how string can be read through the command line. In Java command line... This example demonstrates that how to take input from command line. Here

Ads