-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNegative_Element_To_One_Side.java
More file actions
103 lines (91 loc) · 2.85 KB
/
Negative_Element_To_One_Side.java
File metadata and controls
103 lines (91 loc) · 2.85 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<<<<<<< HEAD
package Learning;
import java.util.Scanner;
public class Negative_Element_To_One_Side {
// *******************Method to display All the Element of the array****************
void Display(int arr[],int n)
{
for(int i=0;i<n;i++)
{
System.out.printf("arr[%d]=%d \n ",i,arr[i]);
}
}
public static void main(String[] args) {
Negative_Element_To_One_Side obj=new Negative_Element_To_One_Side();
Scanner sc=new Scanner(System.in);
System.out.println("Number of Element to be present in the array");
int n=sc.nextInt();
int arr[]=new int[n];
// ************************Loop for Inserting Element is the array**************************
for(int i=0;i<n;i++)
{
System.out.println("Enter the Element to be inserted:");
arr[i]=sc.nextInt();
}
obj.Display(arr,n);
int j=0;
int temp;
for(int i=0;i<n;i++)
{
if(arr[i]<0)
{
if(i !=j )
{
System.out.println("changing");
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
j++;
}
}
System.out.println("********************Printing after rearranging ********************");
obj.Display(arr,n);
}
}
=======
package Learning;
import java.util.Scanner;
public class Negative_Element_To_One_Side {
// *******************Method to display All the Element of the array****************
void Display(int arr[],int n)
{
for(int i=0;i<n;i++)
{
System.out.printf("arr[%d]=%d \n ",i,arr[i]);
}
}
public static void main(String[] args) {
Negative_Element_To_One_Side obj=new Negative_Element_To_One_Side();
Scanner sc=new Scanner(System.in);
System.out.println("Number of Element to be present in the array");
int n=sc.nextInt();
int arr[]=new int[n];
// ************************Loop for Inserting Element is the array**************************
for(int i=0;i<n;i++)
{
System.out.println("Enter the Element to be inserted:");
arr[i]=sc.nextInt();
}
obj.Display(arr,n);
int j=0;
int temp;
for(int i=0;i<n;i++)
{
if(arr[i]<0)
{
if(i !=j )
{
System.out.println("changing");
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
j++;
}
}
System.out.println("********************Printing after rearranging ********************");
obj.Display(arr,n);
}
}
>>>>>>> 870aab09f3780427d91dce8a47621c1c064dbc1d