| | |
Determining output (test yourself!)
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
Hey guys I just ran into some pretty interesting java problems on a different website and thought some of you might get a kick out of this. Determining on how well this goes I may post some more. So here comes problem 1.
Determine the following output with the use of data.txt
data.txt:
5 6 -4 10 -6 7
2 3 6 3 -8 2
4 -9 8 4 9 -3
7 9 2 -3 5 -7
5 -9 -4 7 6 -5
-1 3 8 -4 0 8
Okay guys get at it! Hopefully this will spark a little competitive spirit within the forum...
~IMtheBESTatJAVA
Determine the following output with the use of data.txt
Java Syntax (Toggle Plain Text)
import java.io.File; import java.util.Scanner; import java.io.IOException; class RecArray{ private final static int NUM = 6; private int [][] myGrid = new int[NUM][NUM]; public RecArray(){ load(); } public void load(){ int row, col; String fileName = "data2.txt"; try{ Scanner inFile = new Scanner(new File(fileName)); for (row = 0; row < NUM; row++) for (col = 0; col < NUM; col++) myGrid[row][col] = inFile.nextInt(); }catch(IOException i){ System.out.println("Error: " + i.getMessage()); } } public int calculate(){ return calculate(0); } public int calculate(int count){ if (count >= myGrid.length){ return 0; }else{ int total = 0; for (int i = 0; i <= count; i++){ total += myGrid[count][i]; total += myGrid[i][count]; } total -= myGrid[count][count]; System.out.println("count is: " + count + " and this total is: " + total); return total + calculate(count + 1); } } public void display(){ int row, col; for (row = 0; row < NUM; row++){ for (col =0; col < NUM; col++){ System.out.print(myGrid[row][col] + " "); } System.out.println(); } System.out.println(); } } public static void main(String[] args) { RecArray app = new RecArray(); int answer = app.calculate(); System.out.println("The final answer is: " + answer); }
data.txt:
5 6 -4 10 -6 7
2 3 6 3 -8 2
4 -9 8 4 9 -3
7 9 2 -3 5 -7
5 -9 -4 7 6 -5
-1 3 8 -4 0 8
Okay guys get at it! Hopefully this will spark a little competitive spirit within the forum...
~IMtheBESTatJAVA
Last edited by IMtheBESTatJAVA; Feb 27th, 2009 at 9:08 am.
So answering to this thread would be just showcasing my Java skills as opposed to helping anyone ????
or
Is this a way of disguising your homework ??
or
Is this an assignment which you have copied from the NET and trying to get us to explain the code to ???
Well in the first case I do not have anytime for it and in the second case show us how much effort you put in tracing the execution path and for the third case forget about getting any help.
or
Is this a way of disguising your homework ??
or
Is this an assignment which you have copied from the NET and trying to get us to explain the code to ???
Well in the first case I do not have anytime for it and in the second case show us how much effort you put in tracing the execution path and for the third case forget about getting any help.
Last edited by stephen84s; Feb 27th, 2009 at 10:15 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
Well assuming that this is not homework, I think that it is a good idea.
I know that most of us, including stephen84s, can do this in 30 seconds, but others might learn from it and newbies may test their skill.
Of course the OP could also add the link from which he took the code
I know that most of us, including stephen84s, can do this in 30 seconds, but others might learn from it and newbies may test their skill.
Of course the OP could also add the link from which he took the code
Check out my New Bike at my Public Profile at the "About Me" tab
Last edited by peter_budo; Feb 27th, 2009 at 10:56 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
•
•
This was the worst attempt at disguising homework I've ever seen. Lol.
Unlikely but possible
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
•
•
I always like to give the benefit of the doubt. The OP might not go to that school, and accidentally found about that site, searched it a little and found that assignment and decided to post it.
Unlikely but possible
Note:-
- I still hope that I am wrong.
Last edited by stephen84s; Feb 27th, 2009 at 11:21 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
The name is a joke not a conceited egotistical statement of any sorts. And I'm not taking any courses right now I saved all of these worksheets from an AP Computer Science online course I found a way to access and figured some newer programmers could use problems from them to better themselves. If this was any attempt to disguise my homework and get you guys to do it, wouldn't I have included number 2? Do you guys honestly think I'd just post all the problems right in a row? You can view this post however you want I was just trying to get the community of newer programmers more involved in learning the language other than asking for help. Good job on looking up the worksheet though I figured someone would have done that.
Anyways this didn't turn out quite how I liked it as people would rather spend more time flaming and making accusations based on assumption than actually trying to LEARN. You don't even have to post your answers guys, I just thought this might assess some members' knowledge or maybe certain veterans' retainment. Oh and as to why I didn't repost, I've been too busy with work to check how this turned out. At any rate, I can guarantee that I won't be doing many more of these due to the amount of hostility. You guys obviously have some sort of obsessive compulsive disorders to go this far out of your way to denounce my attempt to actually help people. If anyone wants to know about this problem pm me because posters will just tear us apart.
-IMtheBESTatJAVA (Don't take that literally now you over-analyzing flamers!)
Anyways this didn't turn out quite how I liked it as people would rather spend more time flaming and making accusations based on assumption than actually trying to LEARN. You don't even have to post your answers guys, I just thought this might assess some members' knowledge or maybe certain veterans' retainment. Oh and as to why I didn't repost, I've been too busy with work to check how this turned out. At any rate, I can guarantee that I won't be doing many more of these due to the amount of hostility. You guys obviously have some sort of obsessive compulsive disorders to go this far out of your way to denounce my attempt to actually help people. If anyone wants to know about this problem pm me because posters will just tear us apart.
-IMtheBESTatJAVA (Don't take that literally now you over-analyzing flamers!)
Last edited by IMtheBESTatJAVA; Mar 1st, 2009 at 2:28 pm.
Before anybody else step into this I will said don't do it.
IMtheBESTatJAVA blaming this on the community will not work. You are fully aware of the rule We only give homework help to those who show effort. The above "pretty interesting java problems" does not include any details of what you may think is the out come of this code execution. Given your previous history (yes people keep an eye on other people posting history) and no reply to obvious accusation even though you read our replies you could step in and state your intentions, but you did not do so.
Next time do us and your self favour, provide some possible problem solution and not just copy and paste whatever from wherever assignment.
Now we can continue discussion on top if you want to provide some comments on code, otherwise we may close this post down. Your call...
IMtheBESTatJAVA blaming this on the community will not work. You are fully aware of the rule We only give homework help to those who show effort. The above "pretty interesting java problems" does not include any details of what you may think is the out come of this code execution. Given your previous history (yes people keep an eye on other people posting history) and no reply to obvious accusation even though you read our replies you could step in and state your intentions, but you did not do so.
Next time do us and your self favour, provide some possible problem solution and not just copy and paste whatever from wherever assignment.
Now we can continue discussion on top if you want to provide some comments on code, otherwise we may close this post down. Your call...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- Java question... (Java)
- determining if a checkbox is checked (PHP)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- I lack focus... (Java)
Other Threads in the Java Forum
- Previous Thread: java problem
- Next Thread: Java and HTML development enviornment
| Thread Tools | Search this Thread |
2dgraphics android api apple applet application arguments array arrays automation banking binary binarytree bluetooth capture chat chatprogramusingobjects class classes client code color component count database derby design eclipse eclipsedevelopment encryption error event exception fractal game givemetehcodez graphics gridlayout gui html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list loop macintosh map method methods midlethttpconnection mobile netbeans newbie object os print printing problem producer program programming project projectideas read recursion reference replaysolutions ria scanner screen server set size sms sort sourcelabs sql stop string swing threads transforms tree ui unicode validation windows





