diagonal row of ones
i posted this in the new to java section already but i have only got views and no replies so i am hoping that you guys and gals can help
hey i am writing a program that is suppose to check and see how many rows are in the diagonal, however if there is a zero separating ones the counter is reset. so i understand that from the starting position the counter has to go up one and then over one, i thought i had it. whats wrong with it? can you guys help. oh i know that i am goin to need another loop for the bottom horizontal row right now i am working with the left column.
here is my code:
import java.util.*;
import java.io.*;
import javax.swing.*;
class arf{
publicstaticvoid main(String args[]){
int[][] numberofones =newint[3][4] ;
numberofones[0][2]=1;
//numberofones[1][2]=1;
numberofones[1][1]=1;
numberofones[2][0]=1;
//numberofones[2][2]=1;
numberofones[2][1]=1;
//numberofones[1][2]=1;
numberofones[0][3]=1;
for (int row=0; row < numberofones.length; row++ ){
for (int col=0; col < numberofones[row].length; col++ )
System.out.print( numberofones[row][col] +" ");
System.out.println();
}
System.out.println();
int three,upper;
three=0;
upper=0;
for (int numrows=2;numrows>-1;numrows--){
//System.out.println("Row "+numrows);
three=0;
upper=0;
for (int numcols=0; numcols<3;numcols++){
//System.out.println("Col "+numcols);
if ((numrows+upper<numberofones.length)){
if (numberofones[numrows+upper][numcols]==1){
three=three+1;
//System.out.println("found 1");
}
else{
//System.out.println("found 0");
three=0;
}
upper=upper+1;
}
}
System.out.println(three);
}
if (three==3){
System.out.println("p1 wins");
}
}
}
>
[3456 byte] By [
link33333a] at [2007-11-26 15:05:19]

> i posted this in the new to java section already but
> i have only got views and no replies so i am hoping
> that you guys and gals can help
Well you managed to find both fora. Don't you thing the guys and gals around here read both as well? Or are you the only brainiac that can click on more than one link?
You actions of double posting is akin to asking someone what the time is and then immediately turning to the next person and asking the same thing and so on. Do you think those people would be pissed off.
Lets look specifically at your case. Suppose Fred reads New to Java first and provides you an answer. At the same time Joe reads Java Programming and gives you the same answer. You have wasted someone's time as they are responding to a question already answered.
The moral of the story: don't double post!
> hey i am writing a program that is suppose to check
> and see how many rows are in the diagonal, however if
> there is a zero separating ones the counter is reset.
That's a terrible run-on sentence; care to explain your problem a bit more
clearly and concise?
kind regards,
Jos
You've already been asked at least twice previously not to cross-post:
http://forum.java.sun.com/thread.jspa?threadID=5123412&start=1
And in this posting you where given instructions on how to link postings together so a discussion is held in a single thread.
http://forum.java.sun.com/thread.jspa?threadID=5123373&start=13
So apparently you don't learn from past experiences.
Not only that, you have several postings where you never even bother to reply to the posting to indicate where the suggestion given was helpful or not:
http://forum.java.sun.com/thread.jspa?threadID=5124376
http://forum.java.sun.com/thread.jspa?threadID=5115241
And you wonder why people don't jump to help you out?