Click here to Skip to main content
15,789,840 members
Home / Discussions / Java
   

Java

 
GeneralRe: How to convert 2d array into 1d array in java Pin
Member 1278579115-Oct-16 6:06
Member 1278579115-Oct-16 6:06 
Basically i was trying to do bubble sorting in 2d array with logic
first converted 2d array into 1 d array then sort the elements and again converted back that array into 2d array

class Sort1
{
public static void main(String...avg)
{
int a[][]={{1,2,3,7,12},{4,5},{7,2,6,9,9,11,22,33,44,55}};
//System.out.print(a.length);
int totalelements=0;
for(int x=0;x<a.length;x++)
{
for(int y=0;y<a[x].length;y++)
{
totalelements++;
}
}
//System.out.print(totalelements);
System.out.println("\n"+"unsorted 2d array"+"\n");
for(int i=0;i<a.length;i++)
{
for(int j=0;j<a[i].length;j++)
{
System.out.print(a[i][j]+"\t");
}

System.out.println();
}

System.out.println("\n"+"converted 2d array into 1d array"+"\n");
int b[]=new int[totalelements];
//System.out.print(b.length);
int l=b.length;
int c=0;
for(int k=0;k<a.length;k++)
{
for(int m=0;m<a[k].length;m++)
{
b[c]=a[k][m];
System.out.print(b[c] +"\t");
c++;
}
}

for( int i =1; i<=l-1;i++)
{
for(int j=0; j<l-i;j++)
{
if(b[j]>b[j+1])
{
c =b[j];
b[j]=b[j+1];
b[j+1]=c;
}
}
}
int n=0;
for(int i=0 ; i<a.length ; i++)
{
for(int j=0 ; j<a[i].length ; j++)
{
a[i][j] = b[n];
n++;
}
}
System.out.println("\n"+"\n"+"Sorted 2d array "+"\n");
for(int i=0 ; i<a.length ; i++)
{
for(int j=0 ; j<a[i].length ; j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
QuestionRelating Country to its State & Province Pin
Member 1276860030-Sep-16 0:12
Member 1276860030-Sep-16 0:12 
SuggestionRe: Relating Country to its State & Province Pin
Richard MacCutchan30-Sep-16 0:45
mveRichard MacCutchan30-Sep-16 0:45 
GeneralRe: Relating Country to its State & Province Pin
Member 1276860030-Sep-16 1:17
Member 1276860030-Sep-16 1:17 
GeneralRe: Relating Country to its State & Province Pin
Richard MacCutchan30-Sep-16 1:53
mveRichard MacCutchan30-Sep-16 1:53 
Questioncompile error: string is private with powershell Pin
shoysmTP15-Sep-16 1:53
shoysmTP15-Sep-16 1:53 
AnswerRe: compile error: string is private with powershell Pin
Richard MacCutchan15-Sep-16 2:40
mveRichard MacCutchan15-Sep-16 2:40 
QuestionLoad C++ Library Only Once Pin
Django_Untaken10-Sep-16 10:30
Django_Untaken10-Sep-16 10:30 
AnswerRe: Load C++ Library Only Once Pin
Richard MacCutchan10-Sep-16 21:42
mveRichard MacCutchan10-Sep-16 21:42 
GeneralRe: Load C++ Library Only Once Pin
Django_Untaken11-Sep-16 5:58
Django_Untaken11-Sep-16 5:58 
GeneralRe: Load C++ Library Only Once Pin
Richard MacCutchan11-Sep-16 7:17
mveRichard MacCutchan11-Sep-16 7:17 
QuestionI'm having some issues with a source code Pin
DarkoJava2-Sep-16 16:55
DarkoJava2-Sep-16 16:55 
QuestionJava sector best? Pin
Member 127154721-Sep-16 7:42
Member 127154721-Sep-16 7:42 
QuestionJava sector best? Pin
Member 127154721-Sep-16 7:42
Member 127154721-Sep-16 7:42 
AnswerRe: Java sector best? Pin
NotPolitcallyCorrect1-Sep-16 8:10
NotPolitcallyCorrect1-Sep-16 8:10 
AnswerRe: Java sector best? Pin
ZurdoDev12-Oct-16 2:08
professionalZurdoDev12-Oct-16 2:08 
QuestionExposing API VS Stored procedure Pin
Java Lead31-Aug-16 5:28
Java Lead31-Aug-16 5:28 
AnswerRe: Exposing API VS Stored procedure Pin
Richard MacCutchan31-Aug-16 5:43
mveRichard MacCutchan31-Aug-16 5:43 
QuestionCan not Access RequestAttribute in JSTL Pin
AmbiguousName26-Aug-16 1:46
AmbiguousName26-Aug-16 1:46 
AnswerRe: Can not Access RequestAttribute in JSTL Pin
rah_sin30-Aug-16 21:07
professionalrah_sin30-Aug-16 21:07 
Question[SOLVED] 'TYPE' Cannot Be Resolved To a Type in JSP Pin
Django_Untaken24-Aug-16 3:34
Django_Untaken24-Aug-16 3:34 
QuestionDrools : Exception in thread "main" java.lang.RuntimeException: Query 'results' does not exist Pin
coolSol23-Aug-16 19:37
coolSol23-Aug-16 19:37 
AnswerRe: Drools : Exception in thread "main" java.lang.RuntimeException: Query 'results' does not exist Pin
Richard MacCutchan23-Aug-16 22:02
mveRichard MacCutchan23-Aug-16 22:02 
Questionconsole output to a text file Pin
Member 1142765722-Aug-16 4:55
Member 1142765722-Aug-16 4:55 
AnswerRe: console output to a text file Pin
Richard MacCutchan22-Aug-16 5:28
mveRichard MacCutchan22-Aug-16 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.