Advertisement
aznGiLL

3cccccccccccccccc

Oct 28th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.Scanner; // Scanner
  2.  
  3. public class oppgave3c { // name of the class
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         printNumbersIncreasing();   // call for method printNumbersIncreasing
  8.  
  9.     }
  10.  
  11.     public static void printNumbersIncreasing(){
  12.         Scanner console = new Scanner(System.in);   // scanner decleration
  13.         System.out.print("Oppgi øvre grense: ");
  14.  
  15.         int value = console.nextInt();
  16.         int spaces = 1;
  17.  
  18.         for (int number = 1; number <= value;) {    // for loop
  19.             for (int field = 1; field <= spaces; field++){
  20.                 System.out.printf ("%" + spaces + "d", number);
  21.                 if (number == value){   // if statement that returns the loop if the number is reached
  22.                 return;
  23.                 }
  24.                 number++;
  25.                 }
  26.             System.out.println();
  27.             spaces++;
  28.         }
  29.     }
  30. }
  31.  
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement