Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; // Scanner
- public class oppgave3c { // name of the class
- public static void main(String[] args) {
- printNumbersIncreasing(); // call for method printNumbersIncreasing
- }
- public static void printNumbersIncreasing(){
- Scanner console = new Scanner(System.in); // scanner decleration
- System.out.print("Oppgi øvre grense: ");
- int value = console.nextInt();
- int spaces = 1;
- for (int number = 1; number <= value;) { // for loop
- for (int field = 1; field <= spaces; field++){
- System.out.printf ("%" + spaces + "d", number);
- if (number == value){ // if statement that returns the loop if the number is reached
- return;
- }
- number++;
- }
- System.out.println();
- spaces++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement