首页 > 前端 > 问答 > java课程设计题目及代码大全,java编程题

java课程设计题目及代码大全,java编程题

来源:整理 时间:2024-10-19 18:26:23 编辑:黑码技术 手机版

本文目录一览

1,java编程题

package com.taobao.action; import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.IOException; public class NuberIndex { /**已知一个数组,当用户输入n,则输出比n大的数以及该数在数组中的位置 * @param args * @throws IOException */ @SuppressWarnings("deprecation") public static void main(String[] args) throws IOException { int[] array = {2,3,4,5,6,21,34,7,9,22,20}; System.out.println("请输入一个整数"); DataInputStream in = new DataInputStream(new BufferedInputStream(System.in)); String str = in.readLine(); //这里是读取输入的数 int num = Integer.parseInt(str); //将读取的数转换为整数 for(int i = 0;i

java编程题

2,Java题目请任意输入一个整数如12345将其颠倒输出为54321 该如何

代码如下:123456789101112131415161718public class App public static void main(String[] args) Scanner scanner = new Scanner(System.in); int number = scanner.nextInt(); int result = 0; while (number % 10 != 0) result = result * 10 + number % 10; number /= 10; } System.out.println(result); }}运行结果:

Java题目请任意输入一个整数如12345将其颠倒输出为54321 该如何

3,java经典编程题目

import java.util.*;import javax.swing.JOptionPane;class abc public static void main(String args[]) for(int i=10;i>0;i++) max(); } } public static void yuan() // 计算圆的面积 double x = Double.parseDouble(JOptionPane.showInputDialog("请输入圆的半径:")); double y = x*x; double z = y*Math.PI; JOptionPane.showMessageDialog(null,"圆的面积是:"+z); } public static void ping() // 计算平方根 double x = Double.parseDouble(JOptionPane.showInputDialog("请输入一个数:")); double y = Math.sqrt(x); JOptionPane.showMessageDialog(null,x+"的平方根是:"+y); } public static void rand() // 生成1-100之间的随机数 Random y = new Random(); int rand = y.nextInt(100); JOptionPane.showMessageDialog(null,"随机数:"+rand); } public static void max() // 找出两个数中最大的数(找最小的用Math.min(int a,int b)) int x = Integer.parseInt(JOptionPane.showInputDialog("请输入一个数:")); int y = Integer.parseInt(JOptionPane.showInputDialog("请再输入一个数:")); int max = Math.max(x,y); JOptionPane.showMessageDialog(null,"最大的数是"+max); }}

java经典编程题目

4,java新手编程题目

思路如下:随即4个数字(1~6) 用来模拟4个色子数字全部存入数组ary,.然后升序排列. 如果满足两两相等,那么已经排序好的数字,就是ary[0]=ary[1]; ary[2]=ary[3];然后判断ary[0]+ary[2]==6 .如果等于6 那么满足要求,不等于6 ,那么继续下次循环参考代码1234567891011121314151617181920212223242526272829303132import java.util.Arrays; public class RandomDemo public static void main(String[] args) int loop = 5;// 重复5次试验 for (int k = 0; k < loop; k++) int times = 0;// 循环的次数 int[] ary;// 数组,存储4个随机数 while (true) times++;// 次数+1 ary = new int[4]; for (int i = 0; i < ary.length; i++) ary[i] = getNum();// 添加随机数 } Arrays.sort(ary);// 用数组工具类进行排序 // 因为有两两相等的情况, 那么就是 ary[0]=ary[1] ary[2]=ary[3] 能减少很多的if else判断 // 如果两两相等.且两值和等于6 ,那么跳出循环 if (ary[0] == ary[1] && ary[2] == ary[3] && ary[0] + ary[2] == 6) break;//跳出 } } System.out.println("两个数字分别是" + ary[0] + "和" + ary[2] + "\t" + "循环了" + times + "次"); } } //该方法用于返回一个 [1,6]之间的数字 private static int getNum() return (int) (Math.random() * 6) + 1;// 1~6之间的随即数 }}测试结果12345两个数字分别是1和5 循环了22次两个数字分别是1和5 循环了12次两个数字分别是3和3 循环了105次两个数字分别是1和5 循环了128次两个数字分别是2和4 循环了96次

5,计算机编程java语言题目

******************************************************************** 新建类LuggageFee.java,代码如下: ******************************************************************** import java.util.Scanner; public class LuggageFee public static void main(String[] args) Scanner sc = new Scanner(System.in); while (true) System.out.println("Please input the luggage weight: "); String in = sc.nextLine(); if (in.matches("[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*|[1-9]\\d*")) System.out.println("The " + in.trim() + " luggage fee is: " + getLuggageFee(Double.valueOf(in))); } else System.out.println("Input error, please try again!"); } } } public static double getLuggageFee(double weight) if (weight &lt; 20) return 0; } else if (weight &lt; 40) return (weight - 20) * 0.015; } else return (weight - 20) * 0.015 + (weight - 40) * 2 * 0.015; } } } ******************************************************************** 运行结果如下: ******************************************************************** Please input the luggage weight: -3 Input error, please try again! Please input the luggage weight: 15 The 15 luggage fee is: 0.0 Please input the luggage weight: 25 The 25 luggage fee is: 0.075 Please input the luggage weight: 100 The 100 luggage fee is: 3.0 Please input the luggage weight:

6,java题目

以下是Java中实现题目要求的雇员类(Employee)和经理类(Manager)的代码:```javaimport java.time.LocalDate;import java.util.ArrayList;import java.util.List;public class Employee private String name; private int birthYear; private LocalDate hireDate; private String position; private double salary; public Employee(String name, int birthYear, String position, double salary) this.name = name; this.birthYear = birthYear; this.hireDate = LocalDate.now(); this.position = position; this.salary = salary; } // 打卡上班 public void clockIn() System.out.println(name + " 上班打卡"); } // 下班 public void clockOut() System.out.println(name + " 下班打卡"); } // 上班 public void work() System.out.println(name + " 开始工作"); } public String getName() return name; } public int getBirthYear() return birthYear; } public LocalDate getHireDate() return hireDate; } public String getPosition() return position; } public double getSalary() return salary; }}class Manager extends Employee private String level; private List<Employee> subordinates; public Manager(String name, int birthYear, String position, double salary, String level) super(name, birthYear, position, salary); this.level = level; this.subordinates = new ArrayList<>(); } // 跟下属谈话 public void talkTo(Employee employee) System.out.println(getName() + " 在和 " + employee.getName() + " 谈话"); } // 招聘新雇员 public void hire(Employee employee) subordinates.add(employee); System.out.println(getName() + " 招聘了新员工 " + employee.getName()); } // 辞退雇员 public void fire(Employee employee) subordinates.remove(employee); System.out.println(getName() + " 辞退了员工 " + employee.getName()); } public String getLevel() return level; } public List<Employee> getSubordinates() return subordinates; }}```在以上代码中,Employee类表示普通雇员,包含姓名、出生年份、雇佣日期、岗位、薪水等属性,以及打卡、上班、下班等方法。Manager类继承自Employee类,并增加了岗位级别属性、subordinates属性表示下属列表,以及跟下属谈话、招聘新雇员、辞退雇员等方法。可以编写一个测试类来测试以上两个类的功能,例如:```javapublic class EmployeeManagementSystem public static void main(String[] args) Employee alice = new Employee("Alice", 1990, "Software Engineer", 8000); Employee bob = new Employee("Bob", 1985, "Senior Software Engineer", 12000); Manager charlie = new Manager("Charlie", 1980, "Engineering Manager", 20000, "Director"); alice.clockIn(); bob.clockIn(); alice.work(); bob.work(); alice.clockOut(); bob.clockOut(); charlie.talkTo(alice); charlie.talkTo(bob); charlie.hire(new Employee("David", 1995, "Software Engineer", 7000)); charlie.hire(new Employee("Emily", 1992, "Software Engineer", 8500)); System.out.println(charlie.getName() + " 的下属有:"); for (Employee employee : charlie.getSubordinates()) System.out.println(employee.getName() + "," + employee.getPosition() + "," + employee.getSalary()); } charlie.fire(alice); System.out.println(charlie.getName() + " 的下属有:"); for (Employee employee : charlie.getSubordinates()) System.out.println(employee.getName() + "," + employee.getPosition() + "," + employee.getSalary()); } }}```在以上代码中,首先创建了三个雇员对象,分别是 Alice、Bob 和 Charlie。然后调用它们的打卡、上

7,JAVA程序面向对象程序设计20道题

1.D正确接口应该是:public boolean renameTo(File dest)重新命名此抽象路径名表示的文件2.B,D3.A4. B5. D 参见管道的 APIpublic abstract class Pipeextends Object实现单向管道传送的通道对。 管道由一对通道组成:一个可写入的 sink 通道和一个可读取的 source 通道。一旦将某些字节写入接收器通道,就可以按照与写入时完全相同的顺序从源通道中读取这些字节。 在另一个线程从管道中读取这些字节或先前已写入的字节之前,是否阻塞将该字节写入管道的线程是与系统相关的,因此是未指定的。很多管道实现都对接收器和源通道之间一定数量的字节进行缓冲,但是不应假定会进行这种缓冲。6.A 参见 APIInputStreamReader 是字节流通向字符流的桥梁:它使用指定的 charset 读取字节并将其解码为字符。它使用的字符集可以由名称指定或显式给定,或者可以接受平台默认的字符集。 7.C8.D 没说的9.C10.D Serializable 接口 API 未定义任何方法体11. Chttp://blog.csdn.net/bird_wang/archive/2008/02/28/2128819.aspx三个方法执行顺序repaint() - update() - paint()12.B 看 API:readBytepublic final byte readByte() throws IOException参见 DataInput 的 readByte 方法的常规协定。 从所包含的输入流中读取此操作需要的字节13.B,D 看看方法名字的含义就知道了了嘛14..D 绘制图像,文字15.D这是它的构造方法之定义:public FileOutputStream(File file) throws FileNotFoundException创建一个向指定 File 对象表示的文件中写入数据的文件输出流。创建一个新 FileDescriptor 对象来表示此文件连接16.A17 Dtransient参见:http://www.javaeye.com/wiki/topic/45303618:C19:A由继承关系推导出来:java.lang.Object java.awt.Component java.awt.Container java.awt.Panel java.applet.Applet20.A“发现构造函数要先于init方法执行:”
外面下暴雨了,有空帮你写个://可以算成绩的类,暂且当作班级类import java.util.arrays;import java.util.comparator;public class grade private student[] stus; public grade(student[] stus) super(); this.stus = stus; // 对学生数组按分数排序 arrays.sort(stus, new comparator() { @override public int compare(student s1, student s2) { if (s1.getscore() >= s2.getscore()) { return 1; } else { return -1; } } }); } public student[] getstus() { return stus; } public void setstus(student[] stus) { this.stus = stus; } // 平均成绩 public double avgscore() { double score = 0.0; for (student stu : stus) { score += stu.getscore(); } return score / stus.length; } // 最高分的学生 public student maxscore() { return stus[stus.length - 1]; } // 最低分学生 public student minscore() { return stus[0]; } } /*学生信息类*/ public class student { private int id; private string name; private double score; public student(int id, string name, double score) { super(); this.id = id; this.name = name; this.score = score; } public int getid() { return id; } public void setid(int id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } public double getscore() { return score; } public void setscore(double score) { this.score = score; } } /*测试类*/ public class test { public static void main(string[] args) { //测试类,先创建学生数组,里面有5个学生 student[]stus = new student[]{ new student(1, "zhangsan", 60.0), new student(2, "lisi", 70.0), new student(3, "wangwu", 80.0), new student(4, "mazi", 90.0), new student(5, "baichi", 100.0) }; //创建班级类(就是你要求的那个类) grade g = new grade(stus); system.out.println("平均分是:"+g.avgscore()); system.out.println("最高分是:"+g.maxscore().getname()+"("+g.maxscore().getscore()+"分)"); system.out.println("最低分是:"+g.minscore().getname()+"("+g.minscore().getscore()+"分)"); } } 希望对你有帮助 顺便拜托加点分吧~
cadbcaadcdbbbbba(应该是序列化吧)dbab有几个题我也不确定,因为很少用到Applet.
同意楼上。。。。io还好说点,applet现在既不能上都不用了。。。学来干嘛啊。。。
JAVA程序面向对象程序设计20道题 ???分明是在考IO和Applet

8,Java编程题

原发布者:shensuiliunian浙江工业大学计算机学院《Java程序设计》编程题——赵小敏自编2011一、程序设计基础1、用for语句实现下面的程序ForDemo.java:从10~100以内能被2整数但不能被3整除的整数,要求每行按10个数(数与数之间有一个空格间隔)的形式对其输出。程序的源文件名为PrintPrimeNumber.java。类名为PrintPrimeNumber。2、编写一个getY(doublet)方法,返回值按下列函数计算:t2-10≤t<1t3-2·t-21≤t<3y=t2-t·sint3≤t<5t+15≤t<7t-1其它3、编写一个java应用程序,从键盘输入x,利用下列台劳公式计算cos(x)的值,并输出(要求精确到0.000001)。台劳公式为:cos(x)=1-x2/2!+x4/4!-x6/6!+x8/8!-??4、编写Java独立应用程序,先产生1个随机数n(要求0<n<10),然后随机生成n个0到100之间的随机数,输出这n个随机数的和。5、姐妹素数是指相邻两个奇数均为素数,请编写一个程序SisterPrime.java找出100~1000之间的所有姐妹素数。6、打印出所有的"水仙花数"。所谓"水仙花数"是指一个三位数,其各位数字的立方和等于该数本身。例如:153是一个"水仙花数",因为153=13+53+33。7、求1000之内的所有完全数。所谓完全数,就是一个数恰好等于它的因子之和。例如,6的因子为1,2,3,而6=1+2+3,因此6就是完全数。8、编程求出e=1+1/1!+1/2!+1/3!+?1/n!+?的近似值,当1/n!小于0.0001时停止计算
/*1000道题目,每组10道,共100组,前50组一个规则,后50组一个规则,随机抽取,抽完1000题!*/import java.util.HashSet;import java.util.TreeMap;public class Paper static String[] arr[]= ,srr= public static void main(String[] args) TreeMap<String, HashSet<String>> tm = new TreeMap<String, HashSet<String>>(); for (int i = 0; i < arr.length; i++) //题库! for (int j = 0; j < arr[i].length; j++) arr[i][j] = srr[i] + "" + (j + 1)+"\t"; String key = ""; for(int i=1;i<=100;i++) key=i<10?"第00"+i:i<100?"第0"+i:"第"+i; HashSet<String> hs=new HashSet<String>(); if(i<=50) for(int x=0;x<arr.length;x++) if(x<=0&&hs.size()<6) sect(6,arr[x].length,x,hs); }else if(x==1&&hs.size()<8) sect(8,arr[x].length,x,hs); }else if(x==2&&hs.size()<9) sect(9,arr[x].length,x,hs); }else sect(10,arr[x].length,x,hs); } } tm.put(key, hs); }else for(int x=0;x<arr.length;x++) if(x<=0&&hs.size()<5) sect(5,arr[x].length,x,hs); }else if(x==1&&hs.size()<9) sect(9,arr[x].length,x,hs); }else if(x==2&&hs.size()<10) sect(10,arr[x].length,x,hs); } } tm.put(key, hs); } } for(String s:tm.keySet()) System.out.println(s); for(String s1:tm.get(s)) System.out.print(s1); } System.out.println(); System.out.println(); } } private static void sect(int size, int length,int x,HashSet<String> hs) for (; hs.size() < size;) int p = (int) (Math.random() *length); if(arr[x][p]!=null) hs.add(arr[x][p]); arr[x][p]=null; } } }}
import java.util.scanner; public class array1 { int n=0; int []array; public void method(int x){ boolean flag=false; for(int i=0;i<array.length;i++){ if(x==array[i]){ system.out.print("array["+i+"]"+" "); flag=true; } } if(!flag) system.out.println("not found"); } /** * @param args */ public static void main(string[] args) { // todo auto-generated method stub array1 array1=new array1(); scanner b=new scanner(system.in); //请输入数组长度 system.out.println("请输入数组长度:"); int n =b.nextint(); array1.array = new int[n]; for(int i=0;i<n;i++){ array1.array[i]=b.nextint(); } //请输入数组长度 system.out.println("请输入需要查找的整数:"); int x =b.nextint(); array1.method(x); } }
文章TAG:java课程课程设计设计java课程设计题目及代码大全

最近更新

  • 51822 程序不运行51822 程序不运行

    没有运行程序,为什么我的程序运行出不来?为什么单片机下载了程序却不能运行?你运行?如果你有运行当前的程序,不关闭你写的进程就无法编译-2。1、为啥单片机下载程序了却不能运行啊???没下载.....

    问答 日期:2024-10-19

  • 数据库用在哪些行业,数据库的应用领域有哪些数据库用在哪些行业,数据库的应用领域有哪些

    数据库的应用领域有哪些从软件领域说吧,无论是C/S、B/S架构的软件,只要涉及存储大量数据,一般后台都需要数据库支撑;在电信、金融、零售行业应用特别广泛;本人从事电信行业开发,所以只能提出.....

    问答 日期:2024-10-19

  • 840dsl读取plc插件840dsl读取plc插件

    840dsl如何对脉冲信号进行编码读取利用MCU,单片机读取。西门子840dsl连接电脑时,西门子840Dsl数控系统,如何在840D中用网络接口访问pg/pc?你是840d系统吗?西门子840Dsl数控系统长什么样?840D.....

    问答 日期:2024-10-19

  • 计算机编程入门百度网盘,初学电脑编程入门教程 视频最好计算机编程入门百度网盘,初学电脑编程入门教程 视频最好

    初学电脑编程入门教程视频最好2,计算机编程的基础3,谁有编程初学语言的电子书4,哪有电脑编程初级教程下载5,学习计算机编程入门教材1,初学电脑编程入门教程视频最好http://www.bianceng.cn/.....

    问答 日期:2024-10-19

  • 数据库还有哪些对象,数据库中常用的对象有哪些数据库还有哪些对象,数据库中常用的对象有哪些

    数据库中常用的对象有哪些2,请说出数据库对象具体有哪几个3,数据库的对象有哪些4,asess数据库包括哪些对象其作用分别是什么5,ACCESS数据库可以包含的七类对象是什么1,数据库中常用的对象有.....

    问答 日期:2024-10-19

  • 有哪些法律数据库可以用,比较好的法律查询系统有哪些有哪些法律数据库可以用,比较好的法律查询系统有哪些

    比较好的法律查询系统有哪些2,哪个数据库拥有非洲国家的法律3,法律方面文献在哪些数据库检索4,哪些数据库提供了政策和法律信息的检索5,哪个平台做法律大数据可以在线查询1,比较好的法律查.....

    问答 日期:2024-10-19

  • c停止程序,程序出现一个问题停止工作c停止程序,程序出现一个问题停止工作

    关于c程序停止工作,先解决所有警告。c语言应用程序停止Work变量在创建时需要初始化,一般来说,在C语言中运行停止work后,只要是编译过的,一般来说,C语言中的工作程序停止大多是因为输入输出格.....

    问答 日期:2024-10-19

  • mysql数据库工具有哪些,mysql图形化管理工具 有哪些mysql数据库工具有哪些,mysql图形化管理工具 有哪些

    mysql图形化管理工具有哪些用过的图形化管理工具1、sqlyog2、navicatformysql3、heidisql4、mysql-front感觉sqlyog最好用下面推荐两款:一、Navcat:Navicat是一套快速、可靠并价格相宜的.....

    问答 日期:2024-10-19