java中的程序代碼中心,代碼JAVA

一個簡單的Java程序代碼?

package com.zpp;public class Charge {

創新互聯服務項目包括寶山網站建設、寶山網站制作、寶山網頁制作以及寶山網絡營銷策劃等。多年來,我們專注于互聯網行業,利用自身積累的技術優勢、行業經驗、深度合作伙伴關系等,向廣大中小型企業、政府機構等提供互聯網行業的解決方案,寶山網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到寶山省份的部分城市,未來相信會繼續擴大服務區域并繼續獲得客戶的支持與信任!

public static void main(String [] args) {

if(args.length ==0) {

System.out.println("parameter error!");

System.out.println("java com.zpp.Charge [int]");

return;

}

int min = Integer.parseInt(args[0]);

double money = 0.0;

if (min = 0) {

money =0.0;

System.out.println("not money");

} else if (min = 60) {

money = 2.0;

} else {

money = 2.0 + (min - 60) * 0.01;

}

System.out.println("please pay: " + money);

}

} 編譯:javac -d . Charge.java運行:java com.zpp.Charge 111

Java程序代碼

import java.awt.*;//計算器實例

import java.awt.event.*;

public class calculator

{

public static void main(String args[])

{

MyWindow my=new MyWindow("計算器");

}

}

class MyWindow extends Frame implements ActionListener

{ StringBuffer m=new StringBuffer();

int p;

TextField tex;

Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,jia,jian,cheng,chu,deng,dian,qingling,kaifang;

MyWindow(String s)

{

super(s);

//StringBuffer s2=new StringBuffer();

//String s;

tex=new TextField(18);

b0=new Button(" 0 ");

b1=new Button(" 1 ");

b2=new Button(" 2 ");

b3=new Button(" 3 ");

b4=new Button(" 4 ");

b5=new Button(" 5 ");

b6=new Button(" 6 ");

b7=new Button(" 7 ");

b8=new Button(" 8 ");

b9=new Button(" 9 ");

dian=new Button(" . ");

jia=new Button(" + ");

jian=new Button(" - ");

cheng=new Button(" × ");

chu=new Button(" / ");

deng=new Button(" = ");

qingling=new Button(" 清零 ");

kaifang=new Button(" √ ");

setLayout(new FlowLayout());

add(tex);

add(b0);

add(b1);

add(b2);

add(b3);

add(b4);

add(b5);

add(b6);

add(b7);

add(b8);

add(b9);

add(dian);

add(jia);

add(jian);

add(cheng);

add(chu);

add(kaifang);

add(qingling);

add(deng);

b0.addActionListener(this);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

b4.addActionListener(this);

b5.addActionListener(this);

b6.addActionListener(this);

b7.addActionListener(this);

b8.addActionListener(this);

b9.addActionListener(this);

jia.addActionListener(this);

jian.addActionListener(this);

cheng.addActionListener(this);

chu.addActionListener(this);

dian.addActionListener(this);

deng.addActionListener(this);

qingling.addActionListener(this);

kaifang.addActionListener(this);

setBounds(200,200,160,280);

setResizable(false);//不可改變大小

setVisible(true);

validate();

addWindowListener(new WindowAdapter()

{ public void windowClosing(WindowEvent ee)

{ System.exit(0);

}

});

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==b0)

{

m=m.append("0");

tex.setText(String.valueOf(m));

}

if(e.getSource()==b1)

{

m=m.append("1"); tex.setText(String.valueOf(m));

}

if(e.getSource()==b2)

{

m=m.append("2"); tex.setText(String.valueOf(m));

}

if(e.getSource()==b3)

{

m=m.append("3"); tex.setText(String.valueOf(m));

}

if(e.getSource()==b4)

{

m=m.append("4"); tex.setText(String.valueOf(m));

}

if(e.getSource()==b5)

{

m=m.append("5"); tex.setText(String.valueOf(m));

}

if(e.getSource()==b6)

{

m=m.append("6"); tex.setText(String.valueOf(m));

}

if(e.getSource()==b7)

{

m=m.append("7"); tex.setText(String.valueOf(m));

}

if(e.getSource()==b8)

{

m=m.append("8"); tex.setText(String.valueOf(m));

}

if(e.getSource()==b9)

{

m=m.append("9"); tex.setText(String.valueOf(m));

}

if(e.getSource()==jia)

{

m=m.append("+"); tex.setText(String.valueOf(m));

}

if(e.getSource()==jian)

{

m=m.append("-"); tex.setText(String.valueOf(m));

}

if(e.getSource()==cheng)

{

m=m.append("*"); tex.setText(String.valueOf(m));

}

if(e.getSource()==chu)

{

m=m.append("/"); tex.setText(String.valueOf(m));

}

if(e.getSource()==dian)

{

m=m.append("."); tex.setText(String.valueOf(m));

}

String mm=String.valueOf(m);

int p1=mm.indexOf("+");

int p2=mm.indexOf("-");

int p3=mm.indexOf("*");

int p4=mm.indexOf("/");

if(p1!=-1)

{

p=p1;

}

else if(p3!=-1)

{

p=p3;

}

else if(p2!=-1)

{

p=p2;

}

else if(p4!=-1)

{

p=p4;

}

if(e.getSource()==deng)

{

String m1=mm.substring(0,p);

String m2=mm.substring(p+1);

String ch=mm.substring(p,p+1);

//System.out.println(m1);

//System.out.println(m2);

//System.out.println(ch);

if(ch.equals("+"))

{

float n1=Float.parseFloat(m1);

float n2=Float.parseFloat(m2);

float sum=n1+n2;

String su=String.valueOf(sum);

tex.setText(su);

}

if(ch.equals("-"))

{

float n1=Float.parseFloat(m1);

float n2=Float.parseFloat(m2);

float sum=n1-n2;

String su=String.valueOf(sum);

tex.setText(su);

}

if(ch.equals("*"))

{

float n1=Float.parseFloat(m1);

float n2=Float.parseFloat(m2);

float sum=n1*n2;

String su=String.valueOf(sum);

tex.setText(su);

}

if(ch.equals("/"))

{

float n1=Float.parseFloat(m1);

float n2=Float.parseFloat(m2);

float sum=n1/n2;

String su=String.valueOf(sum);

tex.setText(su);

}

}

if(e.getSource()==qingling)

{StringBuffer kk=new StringBuffer();

m=kk;

tex.setText("0");

// System.out.println(mm);

}

if(e.getSource()==kaifang)

{

String t=tex.getText();

float num=Float.parseFloat(t);

double nub=Math.sqrt(num);

tex.setText(String.valueOf(nub));

}

}

}

Java的基本格式

基本格式:修飾符 class 類名(程序代碼)

意義:Java中的程序代碼都必須放在一個類中,對于類初學者可以簡單地把它理解為一個java程序;類需要使用class作為關鍵字定義;而在class的前面可以有一些修飾符。

擴展資料

編寫java時,特別需要注意的幾個書寫格式常見的錯誤:

1.java中的程序代碼中功能執行語句的最后都必須用(;)結束。

這里需要注意的是,在程序中不要將英文的分號(;)誤寫成中文的分號(;) ,如果寫成了中文的分號,編譯器會報告“Invalid character”(無效字符)這樣的錯誤信息。

2.Java語言是嚴格區分大小寫的。在定義類時,不能將class寫成Class,否則編譯會報錯。程序中定義一個computer的同時,還可以定義一個Computer,computer和Computer是兩個全完不同的符號,在使用的時候需要注意。

3. 在編寫java代碼的時候為了便于閱讀,通常會使用一種良好的格式進行排版,但這并不是必須的,我們也可以在兩個單詞或者符號之間任意換行。

參考資料:百度百科-java

簡單的JAVA的程序代碼的意思?

意思是把x和y轉換成字符串輸出。

當x=0,y=0時,輸出

0 0(空格)

當x=1,y=0時,輸出

0 0 0 1(空格)

所以,最后輸出就是:

0 0 0 1 0 2 0 3 0 4(最后還有一個空格)

用java編寫下圖的程序,詳細程序代碼

我使用eclipse寫的這個練習,首先給你截個圖,抹掉的地方不是這個題的范疇,光標擋住的地方是ModelScore

然后,先是ModelScore代碼:

package?Models;

public?class?ModelScore?{

private?double?mathScore;

private?double?englishScore;

private?double?javaScore;

private?static?final?int?type_Math?=?0,?type_English?=?1,?type_Java?=?2;

public?ModelScore(){

}

public?int?getNumberOfField(){

return?3;

}

public?ModelScore(double?mathScore,?double?englishScore,?double?javaScore){

this.mathScore?=?mathScore;

this.englishScore?=?englishScore;

this.javaScore?=?javaScore;

}

public?double?getMathScore(){

return?this.mathScore;

}

public?double?getEnglishScore(){

return?this.englishScore;

}

public?double?getJavaScore(){

return?this.javaScore;

}

public?void?setMathScore(double?mathScore){

this.mathScore?=?mathScore;

}

public?void?setEnglishScore(double?englishScore){

this.englishScore?=?englishScore;

}

public?void?setJavaScore(double?javaScore){

this.javaScore?=?javaScore;

}

public?double?getAverageScore(){

return?(double)Math.round((this.mathScore?+?this.englishScore?+?this.javaScore)?/?3?*?100)?/?100;

}

public?String?toString(){

return?"Scores:[Math:?"?+?getMathScore()?+?

",?English:?"?+?getEnglishScore()?+?",?Java:?"?+?getJavaScore()?+?

",?AverageScore:?"?+?getAverageScore()?+?"]";

}

public?ModelScore?clone(){

ModelScore?score?=?new?ModelScore();

score.setMathScore(this.getMathScore());

score.setEnglishScore(this.getEnglishScore());

score.setJavaScore(this.getJavaScore());

return?score;

}

public?double?getScore(int?type){

if(type?==?type_Math){

return?mathScore;

}

if(type?==?type_English){

return?englishScore;

}

if(type?==?type_Java){

return?javaScore;

}

return?0;

}

}

然后是ModelStudent代碼:

package?Models;

public?class?ModelStudent?{

private?String?studentID;

private?String?studentName;

private?ModelScore?score;

public?ModelStudent(){

}

public?ModelStudent(String?studentID,?String?studentName,?ModelScore?score){

this.studentID?=?studentID;

this.studentName?=?studentName;

this.score?=?score.clone();

}

public?String?getStudentID(){

return?this.studentID;

}

public?String?getStudentName(){

return?this.studentName;

}

public?ModelScore?getStudentScore(){

return?this.score.clone();

}

public?void?setStudentID(String?studentID){

this.studentID?=?studentID;

}

public?void?setStudentName(String?studentName){

this.studentName?=?studentName;

}

public?void?setStudentScore(ModelScore?score){

this.score?=?score.clone();

}

public?double?getAverageScore(){

return?score.getAverageScore();

}

public?ModelStudent?clone(){

ModelStudent?student?=?new?ModelStudent();

student.setStudentID(studentID);

student.setStudentName(studentName);

student.setStudentScore(score.clone());

return?student;

}

public?String?toString(){

return?"Student:[?ID:?"?+?getStudentID()?+?",?Name:?"

+?getStudentName()?+?",?"?+?getStudentScore()?+?"]";

}

public?String?getNameAndEverayScore(){

return?"Name:?"?+?studentName?+?",?average?score:?"?+?getAverageScore();

}

}

最后是主函數所在的類StudentScoreTester代碼:

import?java.util.ArrayList;

import?java.util.Scanner;

import?Models.ModelScore;

import?Models.ModelStudent;

public?class?StudentScoreTester?{

static?final?int?type_Math?=?0,?type_English?=?1,?type_Java?=?2?;

public?static?void?main(String[]?args)?throws?NumberFormatException{

Scanner?input?=?new?Scanner(System.in);

String?studentID?=?"?",?studentName,?searchedStudentName;

double?studentMathScore,?studentEnglishScore,?studentJavaScore;

ModelScore?studentScore;

ModelStudent?student;

ArrayListModelStudent?students?=?new?ArrayListModelStudent();

ArrayListModelStudent?studentsWithMaxMath,?studentsWithMinMath;

ArrayListModelStudent?studentsWithMaxEnglish,?studentsWithMinEnglish;

ArrayListModelStudent?studentsWithMaxJava,?studentsWithMinJava;

ArrayListModelStudent?searchedStudents;

double[]?averageScores;

double?averageScoreForMath,?averageScoreForEnglish,?averageScoreForJava;

double?maxScoreForMath,?maxScoreForEnglish,?maxScoreForJava;

double?minScoreForMath,?minScoreForEnglish,?minScoreForJava;

while(!studentID.equalsIgnoreCase("end")){

System.out.print("輸入若干學生的學號,姓名,以及三科成績(數學,英語,Java),?以輸入end作為結束輸入:");

studentID?=?input.next();

if(studentID.equalsIgnoreCase("end")){

break;

}

studentName?=?input.next();

studentMathScore?=?Double.valueOf(input.next());

studentEnglishScore?=?Double.valueOf(input.next());

studentJavaScore?=?Double.valueOf(input.next());

studentScore?=?new?ModelScore(studentMathScore,?studentEnglishScore,?studentJavaScore);

student?=?new?ModelStudent(studentID,?studentName,?studentScore);

students.add(student);

}

System.out.println("*******************************");

System.out.println("計算出所有學生平均成績,并以降序顯示......");

sortByAverageScore(students);

for(ModelStudent?everyStudent:?students){

System.out.println(everyStudent.getNameAndEverayScore());

}

System.out.println("*******************************");

System.out.println("全組每科平均成績......");

averageScores?=?calculateAverageScore(students);

averageScoreForMath?=?averageScores[type_Math];

averageScoreForEnglish?=?averageScores[type_English];

averageScoreForJava?=?averageScores[type_Java];

System.out.println("數學:?"?+?averageScoreForMath);

System.out.println("英語:?"?+?averageScoreForEnglish);

System.out.println("Java:?"?+?averageScoreForJava);

System.out.println("*******************************");

System.out.println("每科最好以及最差成績的學生......");

studentsWithMaxMath?=?findStudentWithMaxScore(students,?type_Math);

studentsWithMinMath?=?findStudentWithMinScore(students,?type_Math);

studentsWithMaxEnglish?=?findStudentWithMaxScore(students,?type_English);

studentsWithMinEnglish?=?findStudentWithMinScore(students,?type_English);

studentsWithMaxJava?=?findStudentWithMaxScore(students,?type_Java);

studentsWithMinJava?=?findStudentWithMinScore(students,?type_Java);

System.out.println("??????#########################");

System.out.println("數學最高成績......");

for(ModelStudent?studentWithMaxMath:?studentsWithMaxMath){

System.out.println(studentWithMaxMath.getStudentName()?+?",?"?+?studentWithMaxMath.getStudentScore().getScore(type_Math));

}

System.out.println("\n數學最低成績......");

for(ModelStudent?studentWithMinMath:?studentsWithMinMath){

System.out.println(studentWithMinMath.getStudentName()?+?",?"?+?studentWithMinMath.getStudentScore().getScore(type_Math));

}

System.out.println("??????#########################");

System.out.println("英語最高成績......");

for(ModelStudent?studentWithMaxEnglish:?studentsWithMaxEnglish){

System.out.println(studentWithMaxEnglish.getStudentName()?+?",?"?+?studentWithMaxEnglish.getStudentScore().getScore(type_English));

}

System.out.println("\n英語最低成績......");

for(ModelStudent?studentWithMinEnglish:?studentsWithMinEnglish){

System.out.println(studentWithMinEnglish.getStudentName()?+?",?"?+?studentWithMinEnglish.getStudentScore().getScore(type_English));

}

System.out.println("??????#########################");

System.out.println("Java最高成績......");

for(ModelStudent?studentWithMaxJava:?studentsWithMaxJava){

System.out.println(studentWithMaxJava.getStudentName()?+?",?"?+?studentWithMaxJava.getStudentScore().getScore(type_Java));

}

System.out.println("\nJava最低成績......");

for(ModelStudent?studentWithMinJava:?studentsWithMinJava){

System.out.println(studentWithMinJava.getStudentName()?+?",?"?+?studentWithMinJava.getStudentScore().getScore(type_Java));

}

System.out.println("*******************************");

System.out.print("輸入要查找的學生姓名:?");

input.nextLine();

searchedStudentName?=?input.nextLine();

searchedStudents?=?searchStudentsByName(students,?searchedStudentName);

System.out.println("查找結果是......");

if(searchedStudents.size()?!=?0){

for(ModelStudent?everyStudent:?searchedStudents){

System.out.println(everyStudent);

}

}

else{

System.out.println("查無此學生");

}

}

public?static?void?sortByAverageScore(ArrayListModelStudent?students){

for(int?i?=?0;?i??students.size()?-?1;?i++){

for(int?j?=?i;?j??students.size();?j++){

if(students.get(i).getAverageScore()??students.get(j).getAverageScore()){

ModelStudent?tempStudent?=?students.get(i);

students.set(i,?students.get(j));

students.set(j,?tempStudent);

}

}

}

}

public?static?double[]?calculateAverageScore(ArrayListModelStudent?students){

double[]?averageScore?=?new?double[students.get(0).getStudentScore().getNumberOfField()];

for(int?i?=?0;?i??students.size();?i++){

ModelStudent?currentStudent?=?students.get(i);

averageScore[type_Math]?+=?currentStudent.getStudentScore().getMathScore();

averageScore[type_English]?+=?currentStudent.getStudentScore().getEnglishScore();

averageScore[type_Java]?+=?currentStudent.getStudentScore().getJavaScore();

}

averageScore[type_Math]?=?(double)Math.round(averageScore[type_Math]/?students.size()?*?100)?/?100;

averageScore[type_English]?=?(double)Math.round(averageScore[type_English]/?students.size()?*?100)?/?100;

averageScore[type_Java]?=?(double)Math.round(averageScore[type_Java]/?students.size()?*?100)?/?100;

return?averageScore;

}

public?static?ArrayListModelStudent?findStudentWithMaxScore(ArrayListModelStudent?students,?int?type){

ArrayListModelStudent?studentsWithMaxScore?=?new?ArrayListModelStudent();

ModelStudent?studentWithMaxScore?=?students.get(0);

for(ModelStudent?everyStudent:?students){

if(studentWithMaxScore.getStudentScore().getScore(type)??everyStudent.getStudentScore().getScore(type)){

studentWithMaxScore?=?everyStudent.clone();

}

}

for(ModelStudent?everyStudent:?students){

if(studentWithMaxScore.getStudentScore().getScore(type)?==?everyStudent.getStudentScore().getScore(type)){

studentsWithMaxScore.add(everyStudent);

}

}

return?studentsWithMaxScore;

}

public?static?ArrayListModelStudent?findStudentWithMinScore(ArrayListModelStudent?students,?int?type){

ArrayListModelStudent?studentsWithMaxScore?=?new?ArrayListModelStudent();

ModelStudent?studentWithMaxScore?=?students.get(0);

for(ModelStudent?everyStudent:?students){

if(studentWithMaxScore.getStudentScore().getScore(type)??everyStudent.getStudentScore().getScore(type)){

studentWithMaxScore?=?everyStudent.clone();

}

}

for(ModelStudent?everyStudent:?students){

if(studentWithMaxScore.getStudentScore().getScore(type)?==?everyStudent.getStudentScore().getScore(type)){

studentsWithMaxScore.add(everyStudent);

}

}

return?studentsWithMaxScore;

}

public?static?ArrayListModelStudent?searchStudentsByName(ArrayListModelStudent?students,?String?studentName){

ArrayListModelStudent?resultStudents?=?new?ArrayListModelStudent();

for(ModelStudent?everyStudent:?students){

if(everyStudent.getStudentName().equals(studentName)){

resultStudents.add(everyStudent);

}

}

return?resultStudents;

}

}

分享文章:java中的程序代碼中心,代碼JAVA
網站URL:http://m.kartarina.com/article6/hegoog.html

成都網站建設公司_創新互聯,為您提供小程序開發軟件開發面包屑導航網站導航用戶體驗網站收錄

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

網站優化排名
主站蜘蛛池模板: 亚洲av永久无码精品天堂久久| 精品无码国产AV一区二区三区| 粉嫩大学生无套内射无码卡视频| 亚洲免费日韩无码系列 | 无码人妻精品丰满熟妇区| 久久美利坚合众国AV无码| 中文字幕无码无码专区| 中文无码字幕中文有码字幕| 精品无码一级毛片免费视频观看| 国产在线无码视频一区二区三区| 亚洲av无码兔费综合| 色情无码WWW视频无码区小黄鸭| 在线观看无码的免费网站| 久久青青草原亚洲AV无码麻豆 | 在线观看免费无码专区| 亚无码乱人伦一区二区| 日木av无码专区亚洲av毛片| 久久久无码精品亚洲日韩软件| 亚洲AV无码一区二区一二区 | 亚洲日韩国产精品无码av| 国产亚洲精品无码专区| 无码一区二区三区中文字幕| 亚洲AV无码专区在线电影成人 | 永久免费无码日韩视频| 亚洲GV天堂无码男同在线观看| 色情无码WWW视频无码区小黄鸭 | 日韩人妻无码精品久久免费一 | 国产成年无码v片在线| 亚洲中文字幕无码久久2020 | 国产精品爆乳奶水无码视频 | 免费a级毛片无码a∨免费软件| 无码人妻aⅴ一区二区三区有奶水| 久久久久久AV无码免费网站| 亚洲成a人片在线观看无码专区| 中文字幕无码一区二区免费| 亚洲AV无码日韩AV无码导航| 亚洲VA成无码人在线观看天堂| 夜夜添无码试看一区二区三区| 亚洲AV无码一区二区三区系列| 亚洲AV无码不卡在线播放| 无码A级毛片免费视频内谢|