1、網頁設計實驗報告
2
2、java實驗報告
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Test {
public static void main(String[] args) {
int n ;
List<Integer> list;
list = new ArrayList<Integer>() ;
while(list.size()<10){
n = (int)(Math.random()*100) ;
if(n >= 2 && n<100){
list.add(n) ;
}
}
Iterator<Integer> iter ;
for(iter = list.iterator() ;iter.hasNext();){
int x = iter.next() ;
boolean b = true ;
for(int j = 2 ;j <= Math.sqrt(x); j++){
if(x%j == 0){
b = false ;
}
}
if(b){
System.out.println("隨機數:" + x + " 是素數") ;
}
else{
System.out.println("隨機數:" + x + " 不是素數") ;
}
}
}
}
測試結果1:
隨機數:33 不是素數
隨機數:49 不是素數
隨機數:56 不是素數
隨機數:29 是素數
隨機數:84 不是素數
隨機數:2 是素數
隨機數:37 是素數
隨機數:15 不是素數
隨機數:80 不是素數
隨機數:50 不是素數
測試結果2:
隨機數:12 不是素數
隨機數:26 不是素數
隨機數:59 是素數
隨機數:83 是素數
隨機數:38 不是素數
隨機數:9 不是素數
隨機數:51 不是素數
隨機數:51 不是素數
隨機數:96 不是素數
隨機數:44 不是素數
3、java實驗報告程序
public interface Auth {
public void check(String name,String pwd,AuthResult result);
}
class AuthResult{
public String msg;// 結果信息
public boolean success;// 驗證結果
public boolean isSuccess(){
success;
}
public String getMsg(){
return msg;
}
}
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class Auth1 implements Auth {
Map<String, String> data = new HashMap<String, String>();
@Override
public void check(String name,String pwd,AuthResult result) {
try {
// 載入用戶名和密碼
InputStream in = getClass().getResourceAsStream("Auth1.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String temp = null;
while((temp = br.readLine()) != null){
data.put(temp.split(":")[0], temp.split(":")[1]);
}
if(data.get(name) == null){
result.success = false;
result.msg = "用戶名錯誤";
return;
}
if(!pwd.equals(data.get(name))){
result.success = false;
result.msg = "密碼錯誤";
return;
}
result.success = true;
result.msg = "auth success!";
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class Auth2 implements Auth {
Map<String, String> data = new HashMap<String, String>();
@Override
public void check(String name,String pwd,AuthResult result) {
try {
// 載入用戶名和密碼
InputStream in = getClass().getResourceAsStream("Auth2.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String temp = null;
int i = 1;
String temp1 = null;
while((temp = br.readLine()) != null){
if(i % 2 == 0){
data.put(temp1, temp);
} else {
temp1 = temp;
}
i++;
}
if(data.get(name) == null){
result.success = false;
result.msg = "用戶名錯誤";
return;
}
if(!pwd.equals(data.get(name))){
result.success = false;
result.msg = "密碼錯誤";
return;
}
result.success = true;
result.msg = "auth success!";
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Auth1 a1 = new Auth1();
Auth2 a2 = new Auth2();
Scanner sc = new Scanner(System.in);
String name = null;
String pwd = null;
System.out.println("enter name:");
name = sc.nextLine();
System.out.println("enter pwd:");
pwd = sc.nextLine();
AuthResult result = new AuthResult();
System.out.println("---Auth1---check");
a1.check(name,pwd,result);
if(result.isSuccess()){
System.out.println("auth success!");
} else {
System.out.println("auth fail! because " + result.getMsg());
}
System.out.println("---Auth2---check");
a2.check(name,pwd,result = new AuthResult());
if(result.isSuccess()){
System.out.println("auth success!");
} else {
System.out.println("auth fail! because " + result.getMsg());
}
}
}
文件與這些類同包下應該就能讀到
Auth1.txt
name1:pwd1
name2:pwd2
Auth2.txt
name3
pwd3
name4
pwd4
4、java面向對象程序設計實驗報告怎麼寫
1。People.java
public class People {
//性別(sex)及出生日期(date);方法成員有:獲取人的性別和出生日期及構造方法。要求構造方法可以設置性別和出生日期的初始值。
private int sex;
private Date birth;
public People (int sex, Date birth) {
this.sex = sex;
this.birth = birth;
}
public int getSex() {
return this.sex;
}
public Date getBirth() {
return this.birth;
}
}
2。Student.java
public class Student extends People{
private int sex;
private Date birth;
private String name;
private int stuno;
private double grate;
private String studentNative;
public Student(int sex, Date birth, String name, int stuno, double grate, String studentNative) {
super(sex, birth);
this.name = name;
this.stuno = stuno;
this.grate = grate;
this.studentNative = studentNative;
}
public Date getBirth() {
return birth;
}
public double getGrate() {
return grate;
}
public String getName() {
return name;
}
public int getSex() {
return sex;
}
public String getStudentNative() {
return studentNative;
}
public int getStuno() {
return stuno;
}
}
3。測試類自己編寫就好了,創建一個People和Student的對象,然後設置值,取值就可以了。
五。
1.構造方法沒有返回值,方法名和類名一樣.
2.繼承是指子類可以擁有父類的方法和屬性;多態是指父類的引用可以指向子類對象的實例
3.重寫
4.重載
5、登錄界面java設計的實驗報告,誰來幫忙??
具體點·