11个回答
展开全部
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入要输入正数的个数:");
int count = scan.nextInt();
System.out.println("请输入" + count + "个正数(提示:输入一个数之后按回车键如数第二个):");
int[] array = new int[count];
for (int i = 0; i < count; i++) {
array[i] = scan.nextInt();
}
double totalCount = 0;
double avg = 0;
for (int i = 0; i < array.length; i++) {
totalCount = totalCount + array[i];
}
avg = totalCount / array.length;
System.out.println("大于输入正数的平均数的数、为: ");
for (int i = 0; i < array.length; i++) {
if (array[i] > avg) {
System.out.print( array[i] + " ");
}
}
}
}
public class Test {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入要输入正数的个数:");
int count = scan.nextInt();
System.out.println("请输入" + count + "个正数(提示:输入一个数之后按回车键如数第二个):");
int[] array = new int[count];
for (int i = 0; i < count; i++) {
array[i] = scan.nextInt();
}
double totalCount = 0;
double avg = 0;
for (int i = 0; i < array.length; i++) {
totalCount = totalCount + array[i];
}
avg = totalCount / array.length;
System.out.println("大于输入正数的平均数的数、为: ");
for (int i = 0; i < array.length; i++) {
if (array[i] > avg) {
System.out.print( array[i] + " ");
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Text{
public static void main(String[] args) {
InputStreamReader stdin = new InputStreamReader(System.in);// 键盘输入
BufferedReader bufin = new BufferedReader(stdin);
try {
System.out.print("请输入数字,以空格分割:");
String input = bufin.readLine();
String[] numbers = input.split(" ");
int[] ints = new int[numbers.length];
for (int i = 0; i < numbers.length; i++) {
String number = numbers[i];
ints[i] = Integer.parseInt(number);
}
int sum = 0;
for (int n : ints) {
sum += n;
}
int avg = sum / numbers.length;
for (int n : ints) {
if (n > avg) {
System.out.println(n);
}
}
} catch (IOException E) {
System.out.println("发生I/O错误!!!");
}
}
}
复制出来放入Text.java 中就可以了
import java.io.IOException;
import java.io.InputStreamReader;
public class Text{
public static void main(String[] args) {
InputStreamReader stdin = new InputStreamReader(System.in);// 键盘输入
BufferedReader bufin = new BufferedReader(stdin);
try {
System.out.print("请输入数字,以空格分割:");
String input = bufin.readLine();
String[] numbers = input.split(" ");
int[] ints = new int[numbers.length];
for (int i = 0; i < numbers.length; i++) {
String number = numbers[i];
ints[i] = Integer.parseInt(number);
}
int sum = 0;
for (int n : ints) {
sum += n;
}
int avg = sum / numbers.length;
for (int n : ints) {
if (n > avg) {
System.out.println(n);
}
}
} catch (IOException E) {
System.out.println("发生I/O错误!!!");
}
}
}
复制出来放入Text.java 中就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Ave {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sum=0;
List<Integer> list = new ArrayList<Integer>();
while (true) {
try{
System.out.print("请输入整数:");
int a = sc.nextInt();
sum += a;
list.add(a);
int ave = sum / list.size();
System.out.print("所有大于平均数"+ave+"的值为:");
for (int x : list) {
if (x > ave)
System.out.print(x+" ");
}
System.out.println();
}catch (Exception e) {
String msg = sc.next();
if(msg.equalsIgnoreCase("quit")){
System.out.println("程序退出!");
return;
}
System.out.println("输入错误,请重新输入!");
}
}
}
}
import java.util.List;
import java.util.Scanner;
public class Ave {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sum=0;
List<Integer> list = new ArrayList<Integer>();
while (true) {
try{
System.out.print("请输入整数:");
int a = sc.nextInt();
sum += a;
list.add(a);
int ave = sum / list.size();
System.out.print("所有大于平均数"+ave+"的值为:");
for (int x : list) {
if (x > ave)
System.out.print(x+" ");
}
System.out.println();
}catch (Exception e) {
String msg = sc.next();
if(msg.equalsIgnoreCase("quit")){
System.out.println("程序退出!");
return;
}
System.out.println("输入错误,请重新输入!");
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
class InputData {
private BufferedReader buf = null;
public InputData() {
this.buf = new BufferedReader(new InputStreamReader(System.in));
}
public Set<Integer> getInt(String info, String err) {
Set<Integer> set = new TreeSet<Integer>();
boolean flag = true;
while (flag) {
String str = this.getString(info);
String[] st = str.split(" ");
for (int n = 0; n < st.length; n++) {
if (st[n].trim().matches("^\\d+$")) {
set.add(Integer.parseInt(st[n]));
flag = false;
} else {
set.clear();
System.out.println(err);
}
}
}
return set;
}
public String getString(String info) {
String str = null;
System.out.println(info);
try {
str = this.buf.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public class BiggerThanAvg {
private Set<Integer> set = null;
private Iterator<Integer> iterator = null;
public BiggerThanAvg () {
InputData input = new InputData();
set = new TreeSet<Integer>();
set = input.getInt("请输入数字,用空格分开:", "数字必须为正数");
}
public float getAvg() {
int sum = 0;
int count = 0;
float avg = 0f;
int i = 0;
iterator = set.iterator();
while (iterator.hasNext()) {
i = iterator.next();
sum += i;
count++;
avg = sum / count;
}
return avg;
}
public void returnNumber() {
float avg = this.getAvg();
System.out.println("平均数为:" + avg);
iterator = set.iterator();
boolean flag = true;
if (flag) {
System.out.print("大于平均数的数字:");
int i = 0;
while (iterator.hasNext()) {
i = iterator.next();
if (i > avg) {
System.out.println(i + " ");
}
flag = iterator.hasNext();
}
}
}
public static void main(String args[]) {
BiggerThanAvg btg = new BiggerThanAvg ();
btg.returnNumber();
}
}
请输入数字,用空格分开:
4 6 8
平均数为:6.0
大于平均数的数字:8
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
class InputData {
private BufferedReader buf = null;
public InputData() {
this.buf = new BufferedReader(new InputStreamReader(System.in));
}
public Set<Integer> getInt(String info, String err) {
Set<Integer> set = new TreeSet<Integer>();
boolean flag = true;
while (flag) {
String str = this.getString(info);
String[] st = str.split(" ");
for (int n = 0; n < st.length; n++) {
if (st[n].trim().matches("^\\d+$")) {
set.add(Integer.parseInt(st[n]));
flag = false;
} else {
set.clear();
System.out.println(err);
}
}
}
return set;
}
public String getString(String info) {
String str = null;
System.out.println(info);
try {
str = this.buf.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public class BiggerThanAvg {
private Set<Integer> set = null;
private Iterator<Integer> iterator = null;
public BiggerThanAvg () {
InputData input = new InputData();
set = new TreeSet<Integer>();
set = input.getInt("请输入数字,用空格分开:", "数字必须为正数");
}
public float getAvg() {
int sum = 0;
int count = 0;
float avg = 0f;
int i = 0;
iterator = set.iterator();
while (iterator.hasNext()) {
i = iterator.next();
sum += i;
count++;
avg = sum / count;
}
return avg;
}
public void returnNumber() {
float avg = this.getAvg();
System.out.println("平均数为:" + avg);
iterator = set.iterator();
boolean flag = true;
if (flag) {
System.out.print("大于平均数的数字:");
int i = 0;
while (iterator.hasNext()) {
i = iterator.next();
if (i > avg) {
System.out.println(i + " ");
}
flag = iterator.hasNext();
}
}
}
public static void main(String args[]) {
BiggerThanAvg btg = new BiggerThanAvg ();
btg.returnNumber();
}
}
请输入数字,用空格分开:
4 6 8
平均数为:6.0
大于平均数的数字:8
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Scannner sc=new Scanner=(System.in);
int n=sc.nextInt();
int[]a=new int[n];
int sum;
for(int i=0;i<n;++i){a[i]=sc.nextInt();sum+=a[i];}
int ave=sum/n;
for(int x:a){if(x>ave)System.out.println(x);}
int n=sc.nextInt();
int[]a=new int[n];
int sum;
for(int i=0;i<n;++i){a[i]=sc.nextInt();sum+=a[i];}
int ave=sum/n;
for(int x:a){if(x>ave)System.out.println(x);}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询