Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Logic Help in Tables.. 1

Status
Not open for further replies.

Luckyman1

Technical User
Jan 27, 2003
7
PK
table1 --------------------------------------
key(int) | question_no(int) | answer(String)
--------------------------------------------
1 1 Hi
2 2 Nice
3 2 Cap
4 3 Good
5 3 Job
6 4 Wow!

I need output this way:-

---------------------------------------------
key(int) | question_no(int) | answer(String)
--------------------------------------------
1 1 Hi
2 2 Nice Cap
3 3 Good Job
4 4 Wow!


Can anyone please help me . i'm like a novice to java. and i cant get this to work.
I know its concatenation but i'm at a lost :-(


Code I wrote in Java:-


============================
java class/ getters-setters

Survey.java

public class Survey implements Serializable
{
private String key;
public String question_no;
private String answer;


public String getkey()
{return key;}

public void setkey(String mK)
{this.key = mK; }

public String getquestion_no()
{return question_no; }

public void setquestion_no(String qdesc)
{this.question_no = qdesc;}

public String getanswer()
{return answer;}

public void setanswer(String qNbr)
{this.answer = qNbr;}
============================================================

main class:-

//This is where is the problem, in the logic. I need help here bad !!

SList = dataTestCtrl.RetriveQuestions(); // function to retrieve the database select * from table1
int size = SList.length;

for (int i=0; i < size ; i++)
{
//THis is where i'm totally lost .. please help..

}

=============================================

Thanks again !
-lucky-
 
they have an informix database.
I just need help in the logic part please.

The logic is very dodgey. I know it sounds easy but to me its not working.. :-(

-lucky-
 
Code:
class join
      {
       public static void main(String args[])
              {
               // after reading all data from table1 into arrays
               int question_no[] = {1,2,2,3,3,4}; // assume values in question_no is in ascending or descending order
               String answer[] = {"Hi","Nice","Cap","Good","Job","Wow!"};
               String concate;
               String result[];
               int result_qno[];
               if (answer.length>0)
               { 
                concate = answer[0];
                result =  new String[answer.length];
                result_qno = new int[answer.length];
                int count = 0,lenMinus = answer.length-1;
                for (int i=0; i<lenMinus; i++)
                    {
                     if (question_no[i]!=question_no[i+1])
                        {    
                         result[count] = concate;
                         result_qno[count] = question_no[i];                     
                          count++;
                          concate=answer[i+1];
                          System.out.println(i+"!"+(count)+concate);
                        }
                     else
                         {                          
                          concate=concate+" "+answer[i+1];
                          System.out.println(i+"="+(count)+concate);
                         }
                    }
                result[count] = concate;
                result_qno[count] = question_no[lenMinus];

                for (int m=0;m<=count;m++)
                    System.out.println(result_qno[m]+")"+result[m]);
                }
              }
      }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top