有一个整数序列(可能有重复的整数),现删除指定的某一个整数,输出删除指定数字之后的序列,序列中未被删除数字的前后位置没有发生改变。
若序列中有多个指定的数,需要一起删除。
数据范围:序列长度和序列中的值都满足 
第一行输入一个整数(0≤N≤50)。
第二行输入N个整数,输入用空格分隔的N个整数。
第三行输入想要进行删除的一个整数。
输出为一行,删除指定数字之后的序列。
6 1 2 3 4 5 9 4
1 2 3 5 9
5 1 2 3 4 6 5
1 2 3 4 6
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = in.nextInt();
}
int num = in.nextInt();
for (int i = 0; i < n; i++) { //用了一个比较取巧的方法,没有真正删除
if (nums[i] == num){
continue;
}
System.out.print(nums[i]+" ");
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
int num[] =new int[a];
for(int i =0;i<a;i++) {
num[i] = in.nextInt();
}
int b = in.nextInt();
for(int i =0;i<a;i++) {
if(num[i]!=b) {
System.out.print(num[i]+" ");
}
}
}
}
} import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String nums = sc.nextLine();
String s = sc.nextLine();
ArrayList<Integer> list = new ArrayList<>();
String[] split = s.split(" ");
for (int i = 0; i < split.length; i++) {
int num = Integer.parseInt(split[i]);
list.add(num);
}
String aimnum = sc.nextLine();
int aim = Integer.parseInt(aimnum);
Iterator<Integer> it = list.iterator();
while (it.hasNext()) {
Integer next = it.next();
if (aim == next) {
it.remove();
} else {
System.out.print(next + " ");
}
}
}
} import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
ArrayList<Integer> arr=new ArrayList<Integer>();
for(int i=0;i<a;i++){
arr.add(in.nextInt());
}
int b=in.nextInt();
for(int i=0;i<arr.size();i++){
if(arr.get(i) !=b){
System.out.print(arr.get(i)+" ");
}
}
}
} import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
List<Integer> list=new ArrayList<>();
for(int i=0;i<n;i++){
list.add(sc.nextInt());
}
int x=sc.nextInt();
for(int num:list){
if(num!=x){
System.out.printf("%d ",num);
}
}
}
} import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
int n = scanner.nextInt();
//要输入数据的集合
List<Integer> inputList = new ArrayList<>();
//本来想用remove方法,发现其理解有问题
//将过滤后的数放进一个集合中
List<Integer> toDeleteNumList = new ArrayList<>();
for(int i = 0;i < n;i++){
inputList.add(scanner.nextInt());
}
//要删除的数
int toDeleteNum = scanner.nextInt();
//toDeleteNumList.add(toDeleteNumList);
//将要删除的数与集合中的各元素进行判断,若其中有要删除的数,该数不会添加进新的集合中
for(int j = 0; j < inputList.size();j++){
if(toDeleteNum != inputList.get(j)){
toDeleteNumList.add(inputList.get(j));
}
}
//输出
for(int k = 0;k < toDeleteNumList.size();k++){
System.out.print(toDeleteNumList.get(k) + " ");
}
}
}
} import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int [ ] arr=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
int k=sc.nextInt();//输入需要删除的数字
for(int j=0;j<n;j++){
if(k!=arr[j]) //如果输入的数字和数组中的数字不重复的话就直接打印
//如果重复就直接跳到下一个else里面直接continue
//返回在for循环中重新判断下一个数字,直接跳过重复的数
//跳过重复的数就等于直接不打印这个重复的数
System.out.print(arr[j]+" ");
else continue;
}
}
}
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int lineOne = Integer.parseInt(bufferedReader.readLine());
String[] lineTwo = bufferedReader.readLine().split(" ");
int lineThree = Integer.parseInt(bufferedReader.readLine());
StringBuilder s = new StringBuilder();
for (int i = 0; i < lineOne; i++) {
if (lineThree != Integer.parseInt(lineTwo[i])){
s.append(lineTwo[i]+" ");
}
}
System.out.println(s);
}
} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
}
int x = scanner.nextInt();
for (int item :
a) {
if (item != x) {
System.out.print(item + " ");
}
}
}
scanner.close();
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(sc.nextInt());
}
int m = sc.nextInt();
List<Integer> newList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
if (m != list.get(i)) {
newList.add(list.get(i));
}
}
for (int i = 0; i < newList.size(); i++) {
System.out.print(newList.get(i) + " ");
}
}
}
} import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
// lambda式解法
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
List<String> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
int temp = sc.nextInt();
list.add(Integer.toString(temp));
}
String key = Integer.toString(sc.nextInt());
//使用filter过滤掉key的元素
list = list.stream()
.filter(e->!e.equals(key))
.collect(Collectors.toList());
//每个list元素中间使用空格分割
String s = list.stream().collect(Collectors.joining(" "));
System.out.println(s);
}
}
}