This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

For loop question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello , I have a little pseudo code to write in java. I understand what I have to write I just dont know how to write it in a coding way I guess. Heres the question:
t is a int of size n.
Write a function withoutDuplicate (t) which returns true if the elements of the Array of integers t appear in a unique way in t, and false if not
I understand that if two ints are the same in the array it should return false. otherwise true but how would i write that in a pseudo code.

I have come up with this for now :
for (int i = 0 ; i < arraylenght ; i++

     if (array[i] == array [ i +n]

     return false
 
Marshal
Posts: 24940
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Elie Kassas wrote:Hello , I have a little pseudo code to write in java.



No... "pseudo-code" is not written in Java. It's written in your native language.

That means, first of all, that you don't have to think about the mechanics of Java code while you're trying to think about how to identify the presence or absence of duplicates in an array. It also means that you should be able to use your pseudo-code to explain your process to somebody who doesn't know anything about computer programming. Like maybe your grandmother or your eight-year-old brother or somebody like that.

So to start with you have a set of numbers written down from left to right on a piece of paper. Your task is to explain how to look at that list and find whether it contains any duplicates. You might, for example, start out by saying "Look at the first entry in the list" or maybe "For each entry in the list..."
 
Paul Clapham
Marshal
Posts: 24940
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, welcome to the Ranch!
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many people say pseudo code when they mean code which gives you idea, but might not compile.  (As you know.)
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first suggestion would be to document the requirements.  Your description of the problem is not very clear.

I think this is what you are trying to say:

Given an array of integers, determine if any integer appears more then once.

Then start with some test cases.

A. [123][345][678]
B. [123][456][123]

Then start to think about the different ways which you can iterate through an array.  Remember that you can have multiple pointers into any given array.

 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example of pseudo code
Write a method which will help you decide if you should ask a girl out, ensuring at the same time you do not end up getting your ass kicked!



As you can see the same logic can be written in Afrikaans, Dutch, Marathi or any other human language, and would still make sense.
 
Marshal
Posts: 67412
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Here is an example . . .

Surely you would add endif to terminate each of the ifsA lot of people wouldn't bother about line 3:wink:
That code now shows how you can refine it to make it better.

And what is wrong with elder brothers? I know women who use their elder brother to “filter” men:-
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:And what is wrong with elder brothers?


Elder brother indicates most probably a physically superior individual compared to self. Thus the caution exercised to avoid bodily harm  
 
Paul Clapham
Marshal
Posts: 24940
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William Barnes wrote:Many people say pseudo code when they mean code which gives you idea, but might not compile.  (As you know.)



No, I didn't know that. If they do, it's not a helpful usage of the term. But then that means we don't know what Elie's question really is, so we should wait for them to come back and clarify which kind of pseudo-code was meant.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!