首页 算命 正文

java代码实现算命

1. 用JAVA编写一个简单的算命程序

public class Salary {

/**

* @param args

*/

public static void main(String[] args) {

//用继承,重写方法,都是调用的wages()方法

Person personManager = new Manager();

System.out.println("这个人的工资是:"+personManager.wages());

Person personEngineer = new Engineer();

System.out.println("这个人的工资是:"+personEngineer.wages());

Person personWorker = new Worker();

System.out.println("这个人的工资是:"+personWorker.wages());

}

}

//人类

class Person {

public String wages(){

return "";

}

}

//经理类

class Manager extends Person{

public String wages(){

return "5000/月";

}

}

//工程师类

class Engineer extends Person{

public String wages(){

return "3000/月";

}

}

//工人类

class Worker extends Person{

public String wages(){

return "2000/月";

}

}

2. java编程,用代码实现计算器类(Calculator)

import java.awt.Container;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class TestC { public static void main(String[] args) { IFrame frame = new IFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); }}class IFrame extends JFrame { public static final int width = 200; public static final int height = 200; public IFrame() { setTitle("Welcome"); setSize(width, height); IPanels panel = new IPanels(); Container ContentPane = getContentPane(); ContentPane.add(panel); }}class IPanels extends JPanel implements ActionListener { JLabel res; JTextField num1; JTextField num2; JButton addbtn; JButton subductionbtn; JButton multiplybtn; JButton divisionbtn; public IPanels() { setLayout(new FlowLayout(FlowLayout.LEFT)); res = new JLabel("结果: 0"); JLabel la1 = new JLabel("输入整数a:"); JLabel la2 = new JLabel("输入整数b:"); addbtn = new JButton("+"); subductionbtn = new JButton("—"); multiplybtn = new JButton("*"); divisionbtn = new JButton("/"); num1 = new JTextField(10); num2 = new JTextField(10);add(la1); add(num1); add(la2); add(num2); add(addbtn); add(subductionbtn);add(multiplybtn);add(divisionbtn); add(res); addbtn.addActionListener(this); subductionbtn.addActionListener(this); multiplybtn.addActionListener(this); divisionbtn.addActionListener(this);} public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource()==addbtn){ res.setText(String.valueOf(Integer.parseInt(num1.getText())+Integer.parseInt(num2.getText()))); }else if(e.getSource()==subductionbtn){ res.setText(String.valueOf(Integer.parseInt(num1.getText())-Integer.parseInt(num2.getText()))); }else if(e.getSource()==multiplybtn){ res.setText(String.valueOf(Integer.parseInt(num1.getText())*Integer.parseInt(num2.getText()))); }else if(e.getSource()==divisionbtn){ res.setText(String.valueOf(Integer.parseInt(num1.getText())/Integer.parseInt(num2.getText()))); } }}。

3. 求java代码,要求做一个测试类,实现以下功能之一

println(".println("/输出方法 System; stu.out.out;\t编号\t姓名\t年龄\tJava\tC#\tHtml\tSql\.length;i++){ /!=null){ if(stu.getNum()==num){ return true.length;i++){ if(arr[i]==null){ return i; } } return 9999; } public void create(String name;t平均分"!没有这个学生的存在; } } return false.nextInt()); System.out;添加学生人数已达到上限;t"); } public void update(int num,Student[] arr){// 返回下标 for(int i=0;i<:"\t---!---\arr.*;/输入方法 for(int i=0;i< System.out.println("---更新信息成功---"); this, arr[i])){ System.out.println(arr[i]); return;),Student[] arr){/,Student[] arr){/---更新信息失败---" arr[i].setAge(in.nextInt()), arr[i])){ System.out.println("请输入修改的姓名; public class Admin {// System.out.println(arr[i]); } } } public boolean exist(int num;arr[i].setJava(in,Student stu){/ if(i==9999){ System;arr; String msg=" arr[i].setName(in.length;i++){ if(arr[i]!=null){ arr[i].setSum().exist(num.println(".println("import java.util.println(" arr[i].setAvg();arr;; public void print(Student[] arr){/,Student[] arr){/.out;t总分\/查找方法 System.nextInt()); } //管理类 Scanner in=new Scanner(System;---删除信息成功---".out.next()); }else{ return false; } public void delete(int num,Student[] arr){/.length;i++){ if(this.exist(num, arr[i])){ arr[i]=null; System.out.println("请输入"+arr[i].getName()+"学生的c_sharp成绩:"); if(in.hasNextInt()){ arr[i].setC_sharp(in.nextInt()); } //arr[i].setC_sharp(in.nextInt()); System.out.println("请输入"+arr[i].getName()+"学生的html成绩:"); if(in.hasNextInt()){ arr[i].setHtml(in.nextInt()); } //arr[i].setHtml(in.nextInt()); System.out.println("请输入"+arr[i].getName()+"学生的sql成绩:"); if(in.hasNextInt()){ arr[i].setSql(in.nextInt()); } //arr[i].setSql(in.nextInt()); this.print(arr); break; } } } public void couseSort(int num,Student[] arr){//学科排序方法 if(num==1){ for(int i=0;ijava; private int c_sharp; private int html; private int sql; private int sum; private double avg; public int getNum(){ return num; } public void setNum(int num){ this.num=num; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public int getJava() { return java; } public void setJava(int java) { this.java = java; } public int getC_sharp() { return c_sharp; } public void setC_sharp(int c_sharp) { this.c_sharp = c_sharp; } public int getHtml() { return html; } public void setHtml(int html) { this.html = html; } public int getSql() { return sql; } public void setSql(int sql) { this.sql = sql; } public int getSum() { return sum; } public void setSum() { this.sum =this.java+this.c_sharp+this.html+this.sql; } public double getAvg() { return avg; } public void setAvg() { this.avg = this.sum/4; } public String toString(){ String msg="\t"+this.num+"\t"+this.name+"\t"+this.age+"\t"+this.java+"\t"+this.c_sharp+"\t"+this.html+"\t"+this.sql+"\t"+this.sum+"\t"+this.avg+"\t"; return msg; } } import java.util.*; public class Main {//主 public static void main(String[] args){ Scanner in=new Scanner(System.in); System.out.println("---请定义学生的人数---"); Student[] stuArr=new Student[in.nextInt()]; Admin adminStu=new Admin(); while(true){ System.out.println("---选择你要执行的功能---"); System.out.println("0:添加一个学生"); System.out.println("1:查找一个学生"); System.out.println("2:根据编号更新信息"); System.out.println("3:根据编号删除学生"); System.out.println("4:根据编号输入成绩"); System.out.println("5:根据某门学科排序"); System.out.println("6:根据总分进行排序"); System.out.println("7:退出系统"); //int number =in.nextInt();//判断 String opt=in.next(); 。

4. 谁能帮我解释这段java代码

这样子的题目做得少,看起来费力啊,的确不容易,看看吧import java.util.Scanner;public class myjava { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("请输入人数:"); //人数 int n = scanner.nextInt(); //把没有退出的人设为true,以7个人为例 //flag[0],flag[1],flag[2],flag[3],flag[4],flag[5],flag[6] //都设为true boolean flag[] = new boolean[n]; for(int i=0;i1){ if(flag[index]==true){ count++; if(count==3){ //这里的count记录(从1到3报数),当报数到3时把count的值设为0(即重新从1报数) count = 0; //这里的index记录的是退出人的编号; //设置退出人为false flag[index] = false; //退出一个人,则减少一个,所以减1 left--; } } index++; //当报数报到最后一个人的时候,重新从第一个人开始报数,则把index的值设置为0 if(index==n){ index = 0; } } //前面已经把退出的人设置为false了,那么最后肯定只有一个true,等于true就是还留下的人。

for(int i=0;i

5. 用Java代码写一个程序,简单易懂点

100万个随机数的范围呢,我这是取的1到1000000之间的100万个随机数

import java.util.Arrays;

public class Testc //程序实现对两人同龄与否的判断

{

public static void main(String[] args)

{

int[] a = new int[1000000];

for(int i=0;i<a.length;i++){

a[i]=(int)(Math.random()*1000000+1);

}

Arrays.sort(a);

System.out.println("最小值为:"+a[0]);

System.out.println("最大值为:"+a[999999]);

}

}

6. java的简单代码实现

1)

package com.yck.test;

//我的这个文件的文件名即后缀是:Test.java

public class Test{

private static String str = "主类的文字!!" ;

public static void main(String args[]){

System.out.println(Test.str);

TwoClass twoC = new TwoClass() ;

System.out.println(twoC.str);

ThreeClass threeC = new ThreeClass() ;

System.out.println(threeC.str);

}

}

//第二个类

class TwoClass{

String str = "第二个类的文字!!" ;

}

//第三个类

class ThreeClass{

String str = "第三个类的文字!!" ;

}2)

package com.yck.test;

//我的这个文件的文件名即后缀是:Test.java

public class Test{

private static String str = "主类的文字!!" ;

public static void main(String args[]){

System.out.println(Test.str);

TwoClass twoC = new TwoClass() ;

System.out.println(twoC.str);

ThreeClass threeC = new ThreeClass() ;

System.out.println(threeC.str);

//另一个文件中类的输出

anotherFile anotherfile = new anotherFile() ;

System.out.println(anotherfile.str);

}

}

//第二个类

class TwoClass{

String str = "第二个类的文字!!" ;

}

//第三个类

class ThreeClass{

String str = "第三个类的文字!!" ;

}package com.yck.test;

//这是另一文件,文件名即后缀为:anotherFile.java

public class anotherFile {

String str = "另一个文件中的类!!" ;

}

7. java源代码分析 实在是不太会,求高手教教我

package test2;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.HashMap;import java.util.Map;import java.util.Set;public class JavaCodeAnalyzer { public static void analyze(File file) throws IOException{ //FileOutputStream fos = new FileOutputStream("F;"+File.separator+"result.txt"); if(!(file.getName().endsWith(".txt")||file.getName().endsWith(".java"))){ System.out.println("输入的分析文件格式不对!"); } InputStream is= new FileInputStream(file); BufferedReader br= new BufferedReader(new InputStreamReader(is)); String temp; int count=0; int countSpace=0; int countCode=0; int countDesc=0; Map map = getKeyWords(); while((temp=br.readLine())!=null){ countKeys(temp, map); count++; if(temp.trim().equals("")){ countSpace++; }else if(temp.trim().startsWith("/*")||temp.trim().startsWith("//")){ countDesc++; }else{ countCode++; } } System.out.printf("代码行数:"+countCode+"占总行数的%4.2f\n",(double)countCode/count); System.out.printf("空行数:"+countSpace+"占总行数的%4.2f\n",(double)countSpace/count); System.out.printf("注释行数:"+countDesc+"占总行数的%4.2f\n",(double)countDesc/count); System.out.println("总行数:"+count); System.out.println("出现最多的5个关键字是:"); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println(""); } public static void main(String[] args) { getKeyWords(); File file = new File("F://Test.java"); try { analyze(file); } catch (IOException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } public static Map getKeyWords(){ Map map = new HashMap(); String[]keywords = {"abstract","assert","boolean","break","byte","case","catch","char","class","continue","default","do","double","else","enum","extends","final","finally","float","for","if","implements","import","instanceof","int","interface","long","native","new","package","private","protected","public","return"," strictfp","short","static","super"," switch","synchronized","this","throw","throws","transient","try","void","volatile","while","goto","const"}; for(String s:keywords){ map.put(s, 0); } return map; } public static void countKeys(String s,Map map){ Set keys = map.keySet(); for(String ss:keys){ if(s.indexOf(ss)!=-1){ map.put(ss, map.get(ss)+1); } } }}上班没啥时间了,还有点没写完,你在想想。

8. java代码示例

原发布者:825799700

JAVA编程实例1、publicclassMyClass{privateintval1,val2;publicvoidmyFun(intx,inty){val1=x;val2=y;System.out.println("Thesumis:"+(val1+val2));}publicstaticvoidmain(Stringarg[]){MyClassMyObj=newMyClass();MyObj.myFun(1,2);}}运行结果如下:Thesumis:32、publicclassMyArray{publicstaticvoidmain(String[]args){intmyArray[];//声明数组myArray=newint[10];//创建数组System.out.println("Index\t\tValue");for(inti=0;i<myArray.length;i++)System.out.println(i+"\t\t"+myArray[i]);//证明数组元素默认初始化为0//myArray[10]=100;//将产生数组越界异常}}输出:50503、publicclassArrays{publicstaticvoidmain(String[]args){int[]a1={1,2,3,4,5};int[]a2;a2=a1;for(inti=0;i<a2.length;i++)a2[i]++;for(inti=0;i<a1.length;i++)System.out.println("a1["+i+"]="+a1[i]);}}运行结果:a1[0]=2a1[1]=3a1[2]=4a1[3]=5a1[4]=64、publicclassArrayOfStringsDemo{publicstaticvoidmain(String[]args)