第1个回答 2019-03-20
写了半天··虽然有人块但辛苦了就得传上来!~~~~~~
class
Student{
private
int
sNo;
private
String
sName;
private
int
sAge;
private
double
sScore;
public
Student(int
no,
String
name,
int
age,
double
score)
{
super();
sNo
=
no;
sName
=
name;
sAge
=
age;
sScore
=
score;
}
public
int
getSNo()
{
return
sNo;
}
public
void
setSNo(int
no)
{
sNo
=
no;
}
public
String
getSName()
{
return
sName;
}
public
void
setSName(String
name)
{
sName
=
name;
}
public
int
getSAge()
{
return
sAge;
}
public
void
setSAge(int
age)
{
sAge
=
age;
}
public
double
getSScore()
{
return
sScore;
}
public
void
setSScore(double
score)
{
sScore
=
score;
}
public
static
void
main(String[]args){
Student
s
=
new
Student(1,"zhangsan",15,39);
Student
s1
=new
Student(2,"lisi",18,69);
Student
s2
=
new
Student(3,"wangwu",19,100);
Student
s3
=new
Student(4,"zhaoliu",20,10);
double
num1
=
s.getSScore();
double
num2
=
s1.getSScore();
double
num3
=
s2.getSScore();
double
num4
=s3.getSScore();
double
result
=(num1+num2)/2;
System.out.println(“2人平均成绩"+result);
//
double[]
list
=
{num1,num2,num3};
//
System.out.println(list.length);
double
re
=0
;
if(num1<num2)
{
re
=
num2;
if(num2
<
num3)
{
re
=num3;
}else{re
=num2;}
}else
{
re=num1;
}
System.out.println("最大成绩"+re);
if(num1<num2)
{
re
=num1;
if(num2
<
num3)
{
re
=num2;
if(num3<num4)
{
re=num3;
}else
{
re
=num4;
}
}else
{
re
=num3;
}
}else{re
=num2;}
System.out.println("最小成绩是"+re);
}
}
第2个回答 2009-06-17
1.
public class RandomTest
{
public static void main(String[] args)
{
int a = 0;
int[] count = new int[20];
for(int i=0;i<10000;i++)
{
a = (int)(Math.random()*20+0.5);
for(int j=1;j<=20;j++)
{
if(a==j)
count[j-1]+=1;
}
}
for(int i=0;i<count.length;i++)
{
System.out.print(count[i]+"\t");
if(i==9)
System.out.println();
}
}
}
2.
public class TestRandomChar
{
public static void main(String[] args)
{
char[] RandomArray = new char[10];//10个元素的字符型数组
char temp = ' ';//设置一个 临时替换字符temp 排序的时候用
for (int i = 0; i < 10; i++)//字符数组开始赋值
{
RandomArray[i] = (char) (Math.random() * 200 + 1);//生成字符数组下标为i的元素的值
if(RandomArray[i]>97&&RandomArray[i]<122)//如果生成的值大于97并且小于122 就将其赋值给第i个元素
{
for (int j = 0; j < i; j++)
{
if (RandomArray[j] == RandomArray[i]) //里层的循环是判断 下面生成字符是不是与前面的字符重复 如果重复 重新生成
{
i--;
break;
}
}
}
else
{
i--;
}
}
for (int i = 0; i < RandomArray.length; i++) //输出生成的数组 此时是无序的
{
System.out.print(RandomArray[i]+",");
}
System.out.println();
for(int m=0;m<RandomArray.length;m++)//排序方法
{
for(int n=0;n<=m;n++)
{
if(RandomArray[m]<RandomArray[n])
{
temp = RandomArray[m];
RandomArray[m] = RandomArray[n];
RandomArray[n] = temp;
}
}
}
for (int i = 0; i < RandomArray.length; i++) //输出排序后的数组
{
System.out.print(RandomArray[i]+",");
}
}
}本回答被网友采纳
第3个回答 2009-06-17
1.
public static void main(String[] args) {
int arr[] = new int[21];
for (int i = 0; i < 10000; i++) {
int a=(int)(Math.random()*20+0.5);
if(a<=20){
arr[a]+=1;
}
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
2.
public static void main(String[] args) {
char arrStr[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z'};
char arrChar[] = new char[10];
int count = 0;
int size=26;
while (count < 10) {
int a = (int) (Math.random() * (size));
System.out.print(arrStr[a]+" ");
arrChar[count++]=arrStr[a];
char temp=arrStr[a];
arrStr[a]=arrStr[size-1];
arrStr[size-1]=temp;
size--;
}
System.out.println();
for (int i = 0; i < arrChar.length; i++) {
for (int j = 0; j < arrChar.length; j++) {
if(arrChar[i]<arrChar[j]){
char temp = arrChar[i];
arrChar[i] = arrChar[j];
arrChar[j] = temp;
}
}
}
for (int i = 0; i < arrChar.length; i++) {
System.out.print(arrChar[i]+" ");
}
}