Java - 100 ways to print 1 to 10

electron

New member
Joined
Nov 30, 2010
Messages
1
Points
0
Alright well I'm interested in your creativity and intelligence. I want to see how many possible ways there is to print 1 to 10.

Allow me to start

#1

Code:
public void main(String args[]) {
    for(int i = 1; i < 11; i++)
        System.out.println(i.toString());
}

Note: Java only :)
 
Code:
public static void main(String[] args) {
   int i = 0;
   while(i < 10) {
      i++;
      System.out.println(i);
   }
}
 
System.out.println("1");
System.out.println("2");
System.out.println("3");
System.out.println("4");
System.out.println("5");
System.out.println("6");
System.out.println("7");
System.out.println("8");
System.out.println("9");
System.out.println("10");
 
Code:
public static void main(String[] args) {
   int[] n = {1,2,3,4,5,6,7,8,9,10};
   for(int i : n) {
      System.out.println(i);
   }
}
 
Code:
public static void main(String[] args) {
   int i = 10;
   while(i > 0) {
      i++;
      System.out.println(i);
   }
}

idk
 
Code:
public static void main(String[] args) {
   int i = 10;
   while(i > 0) {
      i++;
      System.out.println(i);
   }
}
idk

That wouldn't work. What you need to do is change the i++ to i-- and swap that around with the print line command.

Like so;

Code:
public static void main(String[] args) {
   int i = 10;
   while(i > 0) {
      System.out.println(i);
      i--;
   }
}

Other than that attempt, well done everyone all of your methods appear to be valid and working correctly (not tested, I just examined them).
 
Just to revive this

class cool{
public static void main(String args[]){
int coolScale = 11;
boolean ifImcoolCuziPostaLot = true;

while (coolScale > 0){
if (ifImcoolCuziPostaLot == true){
System.out.println(--coolScale);
}
}
}
}

Edit: Tested it, works.
Pretty sure it works, I just wrote it now didn't test it so ??
 
Code:
	public static void main(String args[]) {
		for (int i = 1; i <= 100; i++) {
			if (i % 10 == 0) {
				System.out.println(i/10);
			}
		}
	}
 
Code:
	public static void main(String[] args) {
		boolean spammin = true, banned = false;
		int postCount = 1;
		while (spammin && !banned) {
			System.out.println(postCount);
			postCount++;
			if (postCount == 11)
				banned = true;
		}
	}
 
Code:
	public static void main(String[] args) {
		boolean spammin = true, banned = false;
		int postCount = 1;
		while (spammin && !banned) {
			System.out.println(postCount);
			postCount++;
			if (postCount == 11)
				banned = true;
		}
	}

Lol'd Nice!
 
Code:
	public static void main(String[] args) {
		System.out.println("10\n9\n8\n7\n6\n5\n4\n3\n2\n1");
	}
 
Back
Top