Skip to main content
added 45 characters in body
Source Link
user1907906
user1907906

I must display all server names in the range of v10000v10000 up to v10500v10500.
Below is the code that I tried, but sometimes it displays a zero.

String template = "v10";  int count = 0;    while (count < 501) {   String number;     if (count < 100) {   number = "00" + Integer.toString(count);   } else if(count < 10) {   number = "0" + Integer.toString(count);   } else {   number = Integer.toString(count);   }   String server = template + number;   System.out.println(server);   count++;  } 

But when I show this solution to my boss, he just laughs and says, "I can do this better".
How:

I can do this better.

How can I alter my code to make it work properly? I'm new to Java.

I must display all server names in the range of v10000 up to v10500.
Below is the code that I tried, but sometimes it displays a zero.

String template = "v10";  int count = 0;    while (count < 501){   String number;     if(count < 100){   number = "00" + Integer.toString(count);   }else if(count < 10){   number = "0" + Integer.toString(count);   }else{   number = Integer.toString(count);   }   String server = template + number;   System.out.println(server);   count++;  } 

But when I show this solution to my boss, he just laughs and says, "I can do this better".
How can I alter my code to make it work properly? I'm new to Java.

I must display all server names in the range of v10000 up to v10500.
Below is the code that I tried, but sometimes it displays a zero.

String template = "v10"; int count = 0; while (count < 501) { String number; if (count < 100) { number = "00" + Integer.toString(count); } else if(count < 10) { number = "0" + Integer.toString(count); } else { number = Integer.toString(count); } String server = template + number; System.out.println(server); count++; } 

But when I show this solution to my boss, he just laughs and says:

I can do this better.

How can I alter my code to make it work properly? I'm new to Java.

word structure/spell-check
Source Link
Anthony Miller
  • 16.1k
  • 30
  • 74
  • 100

I must display all server names in the range of v10000 up to v10500.
SoBelow is the code that I done this. But my method displaytried, but sometimes it displays a zero too much.

Here's the code:

String template = "v10"; int count = 0; while (count < 501){ String number; if(count < 100){ number = "00" + Integer.toString(count); }else if(count < 10){ number = "0" + Integer.toString(count); }else{ number = Integer.toString(count); } String server = template + number; System.out.println(server); count++; } 

But when I show this solution to my boss, he just laughtlaughs and saidsays, I"I can do this betterbetter".
How can I achievealter my target with a better waycode to make it work properly? I just started with java..I'm new to Java.

I must display all server names in the range of v10000 up to v10500.
So I done this. But my method display sometimes a zero too much.

Here's the code:

String template = "v10"; int count = 0; while (count < 501){ String number; if(count < 100){ number = "00" + Integer.toString(count); }else if(count < 10){ number = "0" + Integer.toString(count); }else{ number = Integer.toString(count); } String server = template + number; System.out.println(server); count++; } 

But when I show this solution to my boss, he just laught and said, I can do this better.
How can I achieve my target with a better way? I just started with java...

I must display all server names in the range of v10000 up to v10500.
Below is the code that I tried, but sometimes it displays a zero.

String template = "v10"; int count = 0; while (count < 501){ String number; if(count < 100){ number = "00" + Integer.toString(count); }else if(count < 10){ number = "0" + Integer.toString(count); }else{ number = Integer.toString(count); } String server = template + number; System.out.println(server); count++; } 

But when I show this solution to my boss, he just laughs and says, "I can do this better".
How can I alter my code to make it work properly? I'm new to Java.

Source Link
user2979186
user2979186

Loop through a counting String value

I must display all server names in the range of v10000 up to v10500.
So I done this. But my method display sometimes a zero too much.

Here's the code:

String template = "v10"; int count = 0; while (count < 501){ String number; if(count < 100){ number = "00" + Integer.toString(count); }else if(count < 10){ number = "0" + Integer.toString(count); }else{ number = Integer.toString(count); } String server = template + number; System.out.println(server); count++; } 

But when I show this solution to my boss, he just laught and said, I can do this better.
How can I achieve my target with a better way? I just started with java...