1. 程式人生 > >java語言基礎實驗報告 第二個實驗

java語言基礎實驗報告 第二個實驗

package njtcstudent.com;

import java.util.Scanner;

public class Seond {

	public static void main(String[] args) {
		 findMax();//給定一組字元,程式設計輸出裡面數值最大者
		reverseOrder();//對陣列中每一個元素賦值後,按逆序輸出
		maxToMinOrder();//對給定一整型陣列,按從大到小順序輸出
		printInt();//給定一個字串,程式設計輸出裡面所包含的數字
		whatNumber();//1000以內的水仙花數
	}

	public static void whatNumber() {
		int ge,shi,bai;
		int i;
		for(i=100;i<1000;i++){
			bai=i/100;
			shi= i%100/10;
			ge=i%100%10;
			if((Math.pow(bai, 3)+Math.pow(shi, 3)+Math.pow(ge, 3))==i)
				System.out.println(i);
		}
	}

	public static void printInt() {
		 String strThree = "sdf92r2t4h423rj23r2fj23";
		 int len = strThree.length();
		 for(int i=0 ;i<len;i++){
			 if(strThree.charAt(i)>='0'&&strThree.charAt(i)<='9')
				 System.out.println(strThree.charAt(i));
		 }
	}

	public static void maxToMinOrder() {
		int[] intarry = {1,5,7,64,87,125,75,48,96,78,56,128,47,25};
		int i,j,temp;
		for(i=0;i<intarry.length;i++)
			for(j=i+1;j<intarry.length;j++)
			{
				if(intarry[j]>intarry[i]){
					temp=intarry[i];
					intarry[i]=intarry[j];
					intarry[j]=temp;
				}
			}
		for(i=0;i<intarry.length;i++){
			System.out.print(intarry[i]+"    ");
			System.out.println();
		}
	}

	public static void reverseOrder() {
		String[] strTwo = {"neijiang","shifan","jike","xueyuan","sofeware","third","class"};
		for(int i=strTwo.length-1;i>=0;i--){
			System.out.println(strTwo[i]);
		}
	}

	public static void findMax() {
		Scanner inputOne = new Scanner(System.in);
		System.out.print("請輸入一個字元:");
		String strlone;
		strlone = inputOne.next();
		int max=strlone.charAt(0);
		int i;
		for(i=1;i<strlone.length();i++){
			if(max<strlone.charAt(i))
				max=strlone.charAt(i);
		}
		System.out.println("The max value is:"+(char)max);
	}

}

2、3班的這個。

4班的第二個實驗報告,只做了第四個,我寫的如下:

package com.njtcstudent.javademo;

import java.util.Scanner;

public class wuliantwo {

	public static void main(String[] args) {
		first();//選擇分支結構那個
		second();//迴圈結構那個

}
	private static void second() {
		int i,s=1;
		for(i=10;i>=1;i--)
		{
			s=s*i;
			System.out.println(i);
		}
		System.out.println("10!的值為:"+s);
	}
	private static void first(){
		Scanner myIn = new Scanner(System.in);
		System.out.println("請輸入一個成績(百分制):");
		int gread;
		gread = myIn.nextInt();
		if(gread>=0 && gread<=100){
			gread=gread%10;
			
			switch(gread){
			case 10:case 9:
				System.out.println("A");
				break;
			case 8:
				System.out.println("B");
				break;
			case 7:
				System.out.println("C");
				break;
			default:
				System.out.println("E");
				
			}
		}
		else
			System.out.println("您輸入的成績有誤!");
	}
	
}