Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @(#)oppgave3b.java
- *
- *
- * @Anders Gill
- * @version 1.00 2011/10/23
- */
- import java.util.Scanner; // Scanner
- public class oppgave3b { // name of the class
- public static void main(String[] args) { // startingbracket for mainz
- printNumbers();
- }
- public static void printNumbers() {
- Scanner console = new Scanner(System.in); // decleration of scanner
- System.out.print("Oppgi øvre grense: "); // requests int maxNumber from user
- int maximumNumber = console.nextInt();
- System.out.print("Oppgi antall tall på hver linje: "); // requests int numbersPerLine from user
- int numbersPerLine = console.nextInt();
- //printNumbers(maxNumber, numbersPerLine); // Prints the numbers thru the method printNumbers
- int counter = 0; // how many numbers currently on the line
- for(int x = 1; x <= maximumNumber; x++) { // startingbracket for the loop
- System.out.printf("%4d", x);
- counter++; // add 1 to the counter because new number on line
- if(counter == numbersPerLine) { // once x amount of numbers are on the line
- System.out.println(); // start new line
- counter = 0; // reset counter, new line
- }
- } // endingbracket for the loop
- } // endingbracket for main
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement