1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
import javax.swing.*;
public class Extra_1
{
private static int user_feedback;
public static void main(String[]args)
{
String output="index\n";
int array_first[]=length();
int array_second[]=length();
create_first(array_first);
create_second(array_second);
int added_array[]=new int[array_first.length+array_second.length];
added(array_first,array_second,added_array);
sort(added_array);
for(int counter=0;counter<added_array.length;counter++)
output+=added_array[counter]+"\n";
print(output);
}
public static void create_first(int array1[])
{
for(int counter=0;counter<array1.length;counter++)
array1[counter]=input(counter);
}
public static void create_second(int array3[])
{
for(int counter=0;counter<array3.length;counter++)
array3[counter]=input(counter);
}
public static int[]length()
{
int user_feeback=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the length of array"));
return new int[user_feedback];
}
public static int input(int number)
{
return number=Integer.parseInt(JOptionPane.showInputDialog(null, "Enter"+number+"the element of array"));
}
public static void added(int array_1[],int array_2[],int array_added[])
{
int counter;
int count;
for(counter=0;counter<array_1.length;counter++)
{
array_added[counter]=array_1[counter];
System.out.println(array_added[counter]);
for(count=0;count<array_2.length;count++)
{
array_added[count+array_1.length]=array_2[count];
System.out.println(array_added[count+array_1.length]);
}
}
public static void sort(int sorting_array[])
{
for(int pass=1;pass<sorting_array.length;pass++)//loop to control number of passes
for(int counter1=0;counter<sorting_array.length-1-(pass-1);counter++)
if(sorting_array[counter]>sorting_array[counter+1])//compare
swap(sorting_array,sorting_array[counter],sorting_array[counter+1]);
}
}
public static void swap(int swappingArray[],int number1,int number2)
{
int temp=number1;
number1=number2;
number2=temp;
}
public static void print(String element)
{
JTextArea outputArea=new JTextArea();
outputArea.setText(element);
JOptionPane.showMessageDialog(null, outputArea,"Arrays",JOptionPane.INFORMATION_MESSAGE);
}
} |
Partager