输入一些数值求出最大值跟最小值

	Scanner s = new Scanner(System.in);
		int max = 0;
		int min = 0;
		int sum = 0;
		while (true) {
			System.out.println("请输入数字");
			int c = s.nextInt();
			if (sum == 0) {
				max = c;
				min = c;
				sum++;
			}
			if (c == 0) {
				System.out.println("程序结束");
				break;
			}
			if (c > max) {
				max = c;
				sum++;

			}
			if (c < min) {
				min = c;
				sum++;

			}
		}
		if (max != 0 && sum != 1) {
			System.out.println("最大值为=" + max);
			System.out.println("最小值为=" + min);
		} else {
			System.out.println("您只输入了1次");
		}
		s.close();
	}

你可能感兴趣的:(输入一些数值求出最大值跟最小值)