mehmet emin

Greenhorn
+ Follow
since Dec 12, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by mehmet emin

Originally posted by Campbell Ritchie:
Write in the assignment that you interpret "until something is not a number" as meaning when you push "enter" after "1 2 3 4"



Could the meaning of the "new line" in the assignment be that? Then I'll be very happy But I want to figure out how to add conditions on the arguments.

Is it possible to test if Integer.parseInt(args[i]) returns an integer or not?
16 years ago
What I don't understand is this, the assignment says "read until something which is not a number appears" but the arguments we send from command line are not numbers already. Does it mean that stop when you encounter an error while parsing the arguments into integers?
16 years ago

Originally posted by Campbell Ritchie:
Is using the command line arguments quite the same as "reading from standard input?" Please ask. You will lose marks if you do the wrong thing.



I don't know if it's true in programming sense but we are asked to do it by using command line arguments.
16 years ago
Actually, my assignment has three parts.
1-Read numbers from standard input into an array until something which is not a number appears (empty line).
2-Calculate something about the array by using a function A.
3-Calculate some other thing about the array by using a function B.

Since mainly it is the first time I'm dealing with java, my intend is not accomplish everything I am asked. I'm just trying to get whatever I can.

Originally posted by Campbell Ritchie:

...But if you do that all in the main method, you have that array as a local variable in the main method, and you will have to pass it elsewhere to be of use elsewhere.



Yes, I will try to pass it to my A and B methods but I'm going step by step to understand everything I'm doing. Firstly, I tried to figure out the command line business and pass the array into a very basic method. I tried to print out the elements of the array like this:



But it prints only the first element of the array. Is my error in myMethod or main?

Originally posted by marc weber:

...Is the intent really to input all the numbers as arguments to main? Or is the program supposed to be more interactive? For example, ask the user for a number, then process it, then ask for another number, then process it... Until the user enters something other than a number?



Does it mean that I have to add some conditions to main or I am doing a more complicated mistake?

edit:--Sorry for this stupid mistake. Above code is working just fine. Ignore that question.
[ December 14, 2008: Message edited by: mehmet emin ]
16 years ago
Hi again,
I have an assignment which requires to read numbers from the standard input into an array until something which is not a number appears (empty line). My instructor added this last bracket particularly and I have no idea how to implement that part but I can think of a way to construct the array similar to this:


But anotherArray=(Integer.parseInt(args[ i ])) didn't put the numbers into the array. Then I thought about replacing it with:



but I determine the args.length by adding numbers (actually strings) to the command line. So the loop will be meaningless. Any clue?
16 years ago
Great, I think I'm getting it. I managed to work this code:



The purpose of the code doesn't matter much. I'm just trying to learn to call some method of a class. So far so good I guess. But how will I send an array of integers as command line argument instead of an integer?

edit:--Sorry, what I really need is to read numbers from command line into an array until something which is not a number appears (empty line). I will try to sort it out. If I can't it, I'll be back then.

[ December 13, 2008: Message edited by: mehmet emin ]
[ December 13, 2008: Message edited by: mehmet emin ]
16 years ago

Originally posted by Henry Wong:


Unfortunately, I think you need to learn classes and object first. With Scheme, functions are first class entities. You can assigned them to variables. You can pass them other functions. etc.

In Java, this is not true. Functions (actually, call methods) are part of classes, or instances of classes.

Henry



Ok, then I have to be in a class environment. Where do I put the method?
Is it like:



or



For the first one, where should I put the main function? Can you give a simple example?

Thanks for the fast reply. I really appreciate any help.
16 years ago
Hi all,

I've been learning scheme for some time and I have no experience on compiled languages. Since scheme is an interpreted and function-based language, I had difficulties to get the basics of java. For example I have an assignment supossed to be written in java that is a function which takes an array and returns a specific element of it. Do I have to work in a class environment such as the array class or another one? What are the ways of giving the input array to the function? I just need to learn the basics but all the tutorials I come across only talks about classes and objects.

Thanks in advance.
16 years ago