Results 1 to 7 of 7

Thread: Insert interger

  1. #1
    yuslaidi is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default Insert interger

    Can anybody help me..

    how to insert 8 integer let say 1,2,3,4,5,6,7,8. then swap that would be 5,6,7,8,1,2,3,4. what the suitable algorithm?

    i need very urgently..

    Pls help..

    Thanks.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    A for loop with 0 and ++ and then a for loop with length and -- ?

  3. #3
    yuslaidi is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default My Coding is Here..

    Hi all....
    My stage 1 and Stage 2 is ok...but my stage 3 had problem
    can anybody help me regarding this....
    it must divide by 2 then for stage 3 output [4] 4, [5],2 [6]6 [7]0 not appear. What should i do.
    Here i put my coding and Output also.

    My Coding


    import java.util.Scanner;
    import java.lang.Math;
    import java.util.Random;



    public class block14 {

    int N;
    protected int m = (int) (Math.log(N) / Math.log(2));
    static Random random = new Random();

    protected int p= (int) (Math.pow(2,(Math.log(N)/Math.log(2)+1)/2));
    int split=N/2;

    public static void main(String[] args){

    System.out.print("Enter Matrix Size : ");

    Scanner scan = new Scanner(System.in);
    int input = scan.nextInt();

    System.out.println("");




    int i,j,x,count;

    int[] outplane = new int[input];
    int[] outplane1 = new int[input];
    int stage=1;
    int plane=0;
    int[] shuffleMatrix = new int[input];



    System.out.println("(STAGE "+stage+")");
    System.out.println("");

    for(i=0; i<input; i++)
    {
    outplane1[i] = i;
    }

    shuffleMatrix = shuffler4(input);
    for ( i = 0; i < input; i++)
    {
    System.out.print( "[" + outplane1[i] + "] "+ shuffleMatrix[i]);
    System.out.println("");

    }


    if (input==2)
    {
    System.out.println("true");
    }

    else {
    int a, b;
    int in = input;


    System.out.println("");



    while(input%2 == 0 && input != 2)
    {


    for (j =0; j<input; j++)
    {
    outplane[j] = shuffleMatrix[j]/2;
    }

    for(j=0; j<input/2; j++)
    {
    for(i=j+1; i<input/2; i++)
    {

    if((outplane[j] == outplane[i]))
    {
    int split1 = outplane1[i];
    int split2 = shuffleMatrix[i];
    int split3 = outplane[i];

    for(int m=i; m<input; m++)
    {
    if(m==(input-1))
    {
    outplane1[m] = split1;
    shuffleMatrix[m] = split2;
    outplane[m] = split3;
    }
    else
    {
    outplane1[m] = outplane1[m+1];
    shuffleMatrix[m] = shuffleMatrix[m+1];
    outplane[m] = outplane[m+1];
    }
    }
    }
    }
    }
    stage++;
    System.out.println("(STAGE "+stage+")");
    System.out.println("");

    for ( i = 0; i < input/2; i++)
    {
    System.out.print( "[" + outplane1[i] + "] "+ shuffleMatrix[i]);
    System.out.println("");

    }




    System.out.println("");
    for ( i = input/2; i < input; i++)
    {
    System.out.print( "[" + outplane1[i] + "] "+ shuffleMatrix[i]);
    System.out.println("");

    }

    System.out.println("");
    input/=2;

    }

    stage++;
    System.out.println(" ");


    }

    }

    public static int[] shuffler4(int lens)
    {
    int[] nums = new int[lens];
    for (int i = 0; i < lens; i++)
    nums[i] = i;

    // shuffle4
    for (int i = 0; i < lens; i++) {
    int r = (int) (Math.random() * (i+1)); // int between 0 and i
    int swap = nums[r];
    nums[r] = nums[i];
    nums[i] = swap;
    }



    return nums;

    }


    }





    Last edited by yuslaidi; 03-10-2011 at 01:01 PM.

  4. #4
    yuslaidi is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    Please guys....is dat anybody can help me??

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Can I ask why this is under the database section?

  6. #6
    yuslaidi is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Can I ask why this is under the database section?
    So, if can't post here where should i?

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

Similar Threads

  1. convert interger value to binary value
    By ahmed80 in forum New To Java
    Replies: 6
    Last Post: 01-21-2011, 11:26 AM
  2. Replies: 3
    Last Post: 02-28-2009, 09:17 AM
  3. trying to convert an interger to a string
    By matpj in forum New To Java
    Replies: 12
    Last Post: 01-15-2009, 10:08 AM
  4. Help with sql insert
    By jmorris in forum New To Java
    Replies: 6
    Last Post: 12-02-2008, 07:05 PM
  5. SQL Insert Help!!!!
    By shaungoater in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 03:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •