第十四章课后作业

 

    第一题

public class Student {
	
	public int id;
	public int heigh;
	
}


 

public class Heigh 
{
	Student[]students=new Student[10];
	public void addStudent(Student student)
	{
		for (int i=0;istudent.heigh)
		{
			student=students[i];
		}
	}	
		return student;
	}
}
import java.util.Scanner;


public class TestHeigh {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Heigh heigh=new Heigh();
		Student student;
		Scanner input=new Scanner(System.in);
		for (int i=0;i<10;i++)
		{
			student=new Student();
			student.id=i+1;
			System.out.print("请输入第"+(i+1)+"名学生的身高");
			student.heigh=input.nextInt();
			heigh.addStudent(student);
		}
		student=heigh.getMaxHeigh();
		System.out.println("该班第"+student.id+"名学生的身高为"+student.heigh);
	}

}


  第二题

 

import java.util.Random;


public class Num {
	int[]nums=new int[100];
	public void initial()
	{
		Random random=new Random();
		for (int i=0; i< nums.length;i++)
		{
			nums [i]=random.nextInt(1001);
			
		}
	} 
	public int getMax(){
		int max=0;
		for (int i=0;imax){
				max=nums[i];
				
			}
		}
		return max;
	}
	public int getMin(){
		int min=nums[0];
		for(int i=0;i


 第四题

import java.util.Random;
public class Num {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		if (isPrime(9))
		{
			System.out.println("是素数");
		}else{
			System.out.println("不是素数");
		}
	}
	public static boolean isPrime(int num)
	{
		boolean b=true;
		
		for (int i=2;i<=Math.sqrt(num);i++)
		{
			if (num%i==0)
			{
				b=false;
			}
		}
		return b;
	}

}


   第五题

import java.util.Random;
import java.util.Scanner;
public class Num {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input=new Scanner(System.in);
		int[]nums=new int[10];
		Random r=new random();
		for (int i=0;iindex;i--)
		{
			nums[i]=nums[i-1];
		}
		nums[index]=value;
	}
}



 

你可能感兴趣的:(第十四章课后作业)