Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Loop from -100 to 100 without using Unary operator

 
Saloon Keeper
Posts: 2610
126
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never used unary operators yet.

Edit : I know what they do though
 
Bartender
Posts: 2230
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

salvin francis wrote:Never used unary operators yet.


Not even unary minus operator? I can't believe!
 
salvin francis
Saloon Keeper
Posts: 2610
126
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paweł Baczyński wrote:Not even unary minus operator? I can't believe!


Nope, didn't use it.
 
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

salvin francis wrote:. . .
Nope, didn't use it.

Bet you 1000000 pints of beer that you have used unary minus. If you still think not please show me a while loop which will print whole numbers from 100 below zero to 100 above zero inclusive.
 
salvin francis
Saloon Keeper
Posts: 2610
126
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


OHHH Silly ME !!!
Of course I have used it

My Bad

I am so used to call -1 "Negative One" that I completely forgot its a unary minus.
 
Campbell Ritchie
Marshal
Posts: 69752
277
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1000000 pintsh of beer pleashe!

If you are ever round here, I shall let you have a 99.9999% discount on that
 
salvin francis
Saloon Keeper
Posts: 2610
126
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:1000000 pintsh of beer pleashe!



for(int n=0;n<1000000;n++){
System.out.prinln( );
System.out.prinln( );
}
 
Paweł Baczyński
Bartender
Posts: 2230
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:If you still think not please show me a while loop which will print whole numbers from 100 below zero to 100 above zero inclusive.


No unary operators
 
Campbell Ritchie
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree: there is ! a unary operator in Paweł's suggestion, !1.
 
Paweł Baczyński
Bartender
Posts: 2230
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got me! Ok, second try
 
salvin francis
Saloon Keeper
Posts: 2610
126
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got you maybe, but they usually restrict unary to mean unary prefix. Actually I was thinking of something completely different with the ! sign.

Try again reading the bang sign as “not”.
 
Paweł Baczyński
Bartender
Posts: 2230
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have used ~
 
Sheriff
Posts: 7638
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should work too if i'm not mistaken
 
Paweł Baczyński
Bartender
Posts: 2230
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be but yeah, it works
 
Liutauras Vilda
Sheriff
Posts: 7638
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And of course if it were an object oriented contest, this should get some extra points
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about the obvious:

 
Campbell Ritchie
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paweł Baczyński wrote:You should have used ~

But you can read the bang sign as not and the post would make sense.

Agree: there is not a unary operator in Paweł's suggestion, not1.

I could hardly write

Agree: there is squiggle a unary operator in Paweł's suggestion, squiggle1.


Nor tilde nor complement.

And be careful I don't move this thread to




Mwaahaahaahaahaahaahaahaahaahaa!





MD.
 
Campbell Ritchie
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was actually trying to suggest another unary operator which SF had probably used and forgotten about. The bang sign !
 
salvin francis
Saloon Keeper
Posts: 2610
126
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote: SF had probably used and forgotten about. The bang sign !


Nope .. I call it "Not", yes I have used it a million times

Here's my entry to shock the judges of the competition
 
Campbell Ritchie
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've done it now!
 
Campbell Ritchie
Marshal
Posts: 69752
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At least I didn't move the thread to MD
 
salvin francis
Saloon Keeper
Posts: 2610
126
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move it to MD,
Change the Topic to :
The craziest way you can loop from -100 to 100 (without unary operator)
 
Rancher
Posts: 1197
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jesper de Jong wrote:What about the obvious:



The ++ is a unary operator. How about for (int i=0-100; i<=100; i += 1) {...}
 
That feels good. Thanks. Here's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic