2个回答
展开全部
随便给你写了一个
package com.wys.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Test {
public static List<Integer> smallNumbers,largeNumbers;
public static int sum1 = 0,sum2 = 0;
public static void main(String[] args) {
smallNumbers = new ArrayList<Integer>();
largeNumbers = new ArrayList<Integer>();
run();
}
public static void run() {
int i = 0;
for (int j = 0; j < 50; j++) {
Random rand = new Random();
i = rand.nextInt(1000);
if (i<500) {
small(i);
}else{
large(i);
}
}
System.out.println("随机输出的50个数字中:");
System.out.println("大于500的数(包括500)共有"+largeNumbers.size()+"个");
System.out.print("他们是"+largeNumbers);
System.out.println();
System.out.println("他们的和是"+sum1);
System.out.println("小于500的数共有"+smallNumbers.size()+"个");
System.out.print("他们是"+smallNumbers);
System.out.println();
System.out.println("他们的和是"+sum2);
}
private static void large(int number) {
largeNumbers.add(number);
sum1 += number;
}
private static void small(int number) {
smallNumbers.add(number);
sum2 += number;
}
}
package com.wys.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Test {
public static List<Integer> smallNumbers,largeNumbers;
public static int sum1 = 0,sum2 = 0;
public static void main(String[] args) {
smallNumbers = new ArrayList<Integer>();
largeNumbers = new ArrayList<Integer>();
run();
}
public static void run() {
int i = 0;
for (int j = 0; j < 50; j++) {
Random rand = new Random();
i = rand.nextInt(1000);
if (i<500) {
small(i);
}else{
large(i);
}
}
System.out.println("随机输出的50个数字中:");
System.out.println("大于500的数(包括500)共有"+largeNumbers.size()+"个");
System.out.print("他们是"+largeNumbers);
System.out.println();
System.out.println("他们的和是"+sum1);
System.out.println("小于500的数共有"+smallNumbers.size()+"个");
System.out.print("他们是"+smallNumbers);
System.out.println();
System.out.println("他们的和是"+sum2);
}
private static void large(int number) {
largeNumbers.add(number);
sum1 += number;
}
private static void small(int number) {
smallNumbers.add(number);
sum2 += number;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package test;
import java.util.Scanner;
public class test {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
String s = input.nextLine();
sort(getMaxValue(s));
}
public static int getMaxValue(String s){
String[] array = s.split(" ");
int max = 0;
for(int i = 0; i < array.length; i++){
int j = Integer.parseInt(array[i]);
if(max < j){
max = j;
}
}
System.out.println("最大值:" + max);
return max;
}
// 将最大值插入某数组并a按从小到大排序
public static void sort(int n){
int[] a = {1, 32, 23, 2, 11};
int[] b = new int[a.length + 1];
for(int i = 0; i < b.length; i++){
if(i == b.length-1){
b[b.length - 1] = n;
break;
}
b[i] = a[i];
}
for(int j = 0; j < b.length; j++){
for(int k = j+1; k < b.length; k++ ){
int temp;
if(b[j] > b[k]){
temp = b[j];
b[j] = b[k];
b[k] = temp;
}
}
}
for(int s=0; s<b.length; s++){
System.out.print(b[s] + " ");
}
}
}
import java.util.Scanner;
public class test {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
String s = input.nextLine();
sort(getMaxValue(s));
}
public static int getMaxValue(String s){
String[] array = s.split(" ");
int max = 0;
for(int i = 0; i < array.length; i++){
int j = Integer.parseInt(array[i]);
if(max < j){
max = j;
}
}
System.out.println("最大值:" + max);
return max;
}
// 将最大值插入某数组并a按从小到大排序
public static void sort(int n){
int[] a = {1, 32, 23, 2, 11};
int[] b = new int[a.length + 1];
for(int i = 0; i < b.length; i++){
if(i == b.length-1){
b[b.length - 1] = n;
break;
}
b[i] = a[i];
}
for(int j = 0; j < b.length; j++){
for(int k = j+1; k < b.length; k++ ){
int temp;
if(b[j] > b[k]){
temp = b[j];
b[j] = b[k];
b[k] = temp;
}
}
}
for(int s=0; s<b.length; s++){
System.out.print(b[s] + " ");
}
}
}
追问
这个执行不了啊,兄弟
在么
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询