Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to print a new line after a certain number of prints
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


geraldine divina
how to print a new line after a certain number of prints
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


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();
            }










}

}


Advertisement
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
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..., BufferedWriter has provide a method newLine() which writes the text into another line. You
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
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
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
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
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
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
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
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
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
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 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... text file line by line and then prints on console. import java.io.
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... automatically prints Prime Number starting from 1 to 50. Example of Prime Number
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 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... an Image: Open an image of the sand to design a foot prints. Selection
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
Line Number Reader Example
Line Number Reader Example      ... class is provide getLineNumber() method to get the number of line. We...(): This method is used to get the number of line. readLine(): This method
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 - 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
How to print this Format exactly?
How to print this Format exactly?   * * * & reverse
Java - How to read a string line per line
Java - How to read a string line per line  Java - How to read a string line per line I am trying to find the tutorial for reading the String line per line. I have a String data, which contains many lines. What is the best way
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 Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... and found that BufferedReader can be used. So, help me and let's know How to Read a file line by line using BufferedReader, efficiently and using less memory
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... demonstrates that how to take input from command line. Here in this example we
 

 

 

DMCA.com