Determining output (test yourself!)

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Closed Thread

Join Date: Oct 2008
Posts: 37
Reputation: IMtheBESTatJAVA has a little shameless behaviour in the past 
Solved Threads: 0
IMtheBESTatJAVA IMtheBESTatJAVA is offline Offline
Light Poster

Determining output (test yourself!)

 
0
  #1
Feb 27th, 2009
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

  1. import java.io.File;
  2. import java.util.Scanner;
  3. import java.io.IOException;
  4.  
  5. class RecArray{
  6.  
  7. private final static int NUM = 6;
  8. private int [][] myGrid = new int[NUM][NUM];
  9.  
  10. public RecArray(){
  11. load();
  12. }
  13.  
  14. public void load(){
  15. int row, col;
  16. String fileName = "data2.txt";
  17. try{
  18. Scanner inFile = new Scanner(new File(fileName));
  19. for (row = 0; row < NUM; row++)
  20. for (col = 0; col < NUM; col++)
  21. myGrid[row][col] = inFile.nextInt();
  22. }catch(IOException i){
  23. System.out.println("Error: " + i.getMessage());
  24. }
  25. }
  26.  
  27. public int calculate(){
  28. return calculate(0);
  29. }
  30.  
  31. public int calculate(int count){
  32. if (count >= myGrid.length){
  33. return 0;
  34. }else{
  35. int total = 0;
  36. for (int i = 0; i <= count; i++){
  37. total += myGrid[count][i];
  38. total += myGrid[i][count];
  39.  
  40. }
  41. total -= myGrid[count][count];
  42. System.out.println("count is: " + count + " and this total is: "
  43. + total);
  44. return total + calculate(count + 1);
  45. }
  46. }
  47.  
  48.  
  49.  
  50.  
  51. public void display(){
  52. int row, col;
  53. for (row = 0; row < NUM; row++){
  54. for (col =0; col < NUM; col++){
  55. System.out.print(myGrid[row][col] + " ");
  56. }
  57. System.out.println();
  58. }
  59. System.out.println();
  60. }
  61.  
  62. }
  63.  
  64. public static void main(String[] args) {
  65. RecArray app = new RecArray();
  66. int answer = app.calculate();
  67. System.out.println("The final answer is: " + answer);
  68. }

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.
Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Determining output (test yourself!)

 
1
  #2
Feb 27th, 2009
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.
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 ?"
Quick reply to this message  
Join Date: Dec 2007
Posts: 1,677
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 226
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Determining output (test yourself!)

 
0
  #3
Feb 27th, 2009
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
Check out my New Bike at my Public Profile at the "About Me" tab
Quick reply to this message  
Join Date: Dec 2004
Posts: 4,197
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Determining output (test yourself!)

 
2
  #4
Feb 27th, 2009
Homework by may search, from Palo Verde High School (home page) and teacher name is Ms. Chang( class site)
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
Quick reply to this message  
Join Date: Sep 2008
Posts: 1,597
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Determining output (test yourself!)

 
0
  #5
Feb 27th, 2009
This was the worst attempt at disguising homework I've ever seen. Lol.
Quick reply to this message  
Join Date: Dec 2007
Posts: 1,677
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 226
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Determining output (test yourself!)

 
0
  #6
Feb 27th, 2009
Originally Posted by BestJewSinceJC View Post
This was the worst attempt at disguising homework I've ever seen. Lol.
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
Check out my New Bike at my Public Profile at the "About Me" tab
Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Determining output (test yourself!)

 
0
  #7
Feb 27th, 2009
Originally Posted by javaAddict View Post
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
I too was secretly wishing that this wasn't some attempt at disguising homework, but the fact that the O.P. after reading the first two responses from me and you didn't dare post again (even though I saw him as one the viewers of the thread at the bottom), gives a clue as to what he was trying to do.

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 ?"
Quick reply to this message  
Join Date: Feb 2009
Posts: 17
Reputation: Taniotoshi is an unknown quantity at this point 
Solved Threads: 0
Taniotoshi's Avatar
Taniotoshi Taniotoshi is offline Offline
Newbie Poster

Re: Determining output (test yourself!)

 
0
  #8
Feb 28th, 2009
I am the best at java... Interesting statement. Does ego help at programming? Apparently, it surely does not help at getting a homework done
and some people still think our thoughts do not reach computers...
Quick reply to this message  
Join Date: Oct 2008
Posts: 37
Reputation: IMtheBESTatJAVA has a little shameless behaviour in the past 
Solved Threads: 0
IMtheBESTatJAVA IMtheBESTatJAVA is offline Offline
Light Poster

Re: Determining output (test yourself!)

 
-1
  #9
Mar 1st, 2009
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!)
Last edited by IMtheBESTatJAVA; Mar 1st, 2009 at 2:28 pm.
Quick reply to this message  
Join Date: Dec 2004
Posts: 4,197
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Determining output (test yourself!)

 
1
  #10
Mar 1st, 2009
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...
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
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC