你的题有很多错误,我给你改了一下。
公司主营业务:成都网站制作、做网站、外贸营销网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出任城免费做网站回馈大家。
1.设变量i和j的定义如下,试分别计算下列表达式的值:
int i=1; double d=1.0;
1题 35/4 [8]
2题 46%9+4*4-2 [15]
3题 45+43%5*(23*3%2)[48]
4题 45+45*50%i-- [45]
5题 45+45*50%(i--) [45]
6题 1.5*3+(++d) [6.5]
7题 1.5*3+d++ [5.5]
8题 i+=3/i+3 [7]
程序阅读题
1给定如下代码,写出程序运行结果
class Example{
public static void main(String arges[]){
int i=0;
do{
System.out.println("doing it for i is:"+i);
}while(--i0);
System.out.println("finish");
}
}
结果如下:
doing it for i is:0
finish
2 阅读程序段写出执行结果
for(int k=1;k=5;k++){
if(k4)break;
System.out.println("k="+k);
}
结果:
k=1
k=2
k=3
k=4
3试写出下列程序段循环的运行结果
int i=1;
while(i10)
if(i++%2==0)
System.out.println(i);
结果:
3
5
7
9
操作题
求1!+2!+...+10!
public static void main(String arges[]){
long sum = 0;
for(int i = 1; i = 10; i++) {
long s = 1;
for(int j = 1; j = i; j++) {
s *= j;
}
sum += s;
}
System.out.println("sum = " + sum);
}
求100之内的所有“完数”。完数是指等于它的因子和的数。例如:6=1+2+3,6=1*2*3,则6是一个完数
public class wanshu{
public static void main(String[] args) {
for(int i = 1; i = 100; i++) {
if(fun(i)) {
System.out.println(i);
}
}
}
public static boolean fun(int num) {
int sum = 0;
for(int i = 1; i num; i++) {
if(num % i == 0) {
sum += i;
}
}
return num == sum;
}
}
java课程设计题目及代码分别是:
1、题目:计算器。设计内容是设计一个图形界面(GUI)的计算器应用程序,完成简单的算术运算。
设计要求是设计的计算器应用程序可以完成家法、减法、乘法、除法和取余运算。且有小数点、正负号、求倒数、退格和清零功能。
2、代码:
数字按钮NumberButton类如下:
import java.awt.
import java.awt.event.
import javax.swing.
public class NumberButton extends Button.
{
int number.
public NumberButton(int number).
{
super(""+number).
this.number=number.
setForeground(Color.blue).
}
public int getNumber().
{
return number;
}
}
其它java课程设计题目及代码是:
题目:华容道。编写一个按钮的子类,使用该子类创建的对象代表华容道中的人物。通过焦点事件控制人物颜色,当人物获得焦点时颜色为蓝色,当失去焦点时颜色为灰色。
通过键盘事件和鼠标事件来实现曹操、关羽等人物的移动。当人物上发生鼠标事件或键盘事件时,如果鼠标指针的位置是在人物的下方(也就是组件的下半部分)或按下键盘的“↓“键,该人物向下移动。向左、向右和向上的移动原理类似。
代码是:
String name[]={"曹操","关羽","张","刘","马","许","兵","兵","兵","兵"}.
for(int i=0;iname.length;i++).
{
person[i]=new Person(i,name[i]).
person[i].addKeyListener(this).
person[i].addMouseListener(this).
// person[i].addFocusListener(new Person).
add(person[i]).
}
person[0].setBounds(104,54,100,100).
person[1].setBounds(104,154,100,50).
person[2].setBounds(54,154,50,100).
person[3].setBounds(204,154,50,100).
person[4].setBounds(54,54,50,100).
person[5].setBounds(204,54,50,100);
person[6].setBounds(54,254,50,50);
person[7].setBounds(204,254,50,50);
person[8].setBounds(104,204,50,50);
person[9].setBounds(154,204,50,50);
按照题目要求编写的用javaBean规范设计的学生类Student的Java程序如下
需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果
Student.java文件代码如下
package user.java.test;
import java.io.Serializable;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private String no;
private String name;
private double score;
public Student(){}
public Student(String no,String name,double score){
this.no=no;
this.name=name;
this.score=score;
}
public String getNo(){ return no;}
public void setNo(String no){ this.no=no;}
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 String toString(){
return "学号:"+no+",姓名:"+name+",成绩:"+score;
}
public static double getAvg(Student[] sArray){
double sum=0,avg;
for(int i=0;isArray.length;i++){
sum=sum+sArray[i].getScore();
}
avg=sum/sArray.length;
return avg;
}
}
Test.java文件代码如下
package user.java.test;
public class Test{
public static void main(String[] args){
Student[] sArray=new Student[5];
sArray[0]=new Student("001","张三",89.5);
sArray[1]=new Student("002","李四",82.5);
sArray[2]=new Student("003","王五",93);
sArray[3]=new Student("004","赵六",73.5);
sArray[4]=new Student("005","孙七",66);
System.out.println("这些学生的平均分:"+Student.getAvg(sArray));
for(int i=0;isArray.length;i++){
System.out.println(sArray[i].toString());
}
}
}
好了,你测试一下咯!
public interface ShapeArea {//定义ShapeArea接口
public double getArea();//double getArea( ):求一个形状的面积
public double getPerimeter();// Double getPerimeter( ):求一个形状的周长。
}
public class MyTriangle implements ShapeArea {
double x,y,z,s;//x,y,z :double型,表示三角形的三条边
public MyTriangle(double x, double y, double z) {//方法:MyTriangle(double x, double y, double z):构造函数,给三条边和s赋值;
this.x = x;
this.y = y;
this.z = z;
this.s = (x+y+z)/2;
}
@Override
public double getArea() {
return Math.sqrt(this.s*(this.s-this.x)*(this.s-this.y)*(this.s-this.z));
}
@Override
public double getPerimeter() {
return (x+y+z);
}
@Override
public String toString() {
System.out.print("此三角形的面积和周长为:");
return this.getArea()+"、"+this.getPerimeter();
}
}
public class Test {//测试类
public static void main(String[] args) {
MyTriangle myTriangle = new MyTriangle(3, 4, 5);
System.out.println(myTriangle);
}
}
3, 文件名:Three.java
public class Three {
public static void main(String[] args) {
Student stu = new Student("Zhang San", true, (short)12);
System.out.println("Student name: " + stu.name);
System.out.println("Student is a male?: " + stu.sex);
System.out.println("Student's age: " + stu.age);
stu.work();
stu.study();
Teacher teacher = new Teacher();
teacher.learnMoney();
}
}
abstract class Person{//抽象类Person
protected String name;
protected boolean sex;
protected short age;
protected abstract void work(); //work抽象方法
}
interface Learnmoney{//Learnmoney接口
public void learnMoney();
}
interface Study{//Study接口
public void study();
}
class Student extends Person implements Study{//Student类
public void work() {
System.out.println("学生的工作是努力学习");
}
public Student(String name, boolean sex, short age){
super.name = name;
super.sex = sex;
super.age = age;
}
public void study() {
System.out.println("学生正在学习");
}
}
class Teacher extends Person implements Learnmoney{
public void work() {
System.out.println("教师的工作是教书育人");;
}
public void learnMoney() {
System.out.println("教师正在赚钱");
}
}
class Docotor extends Person implements Learnmoney{
public void work() {
System.out.println("医生的职责是救死扶伤");
}
public void learnMoney() {
System.out.println("医生正在赚钱");
}
}
------------------------------------
4文件名:Four.java
public class Four {
public static void main(String[] args) {
Rectangle r = new Rectangle(3, 4);
System.out.println("Area is : " + r.area());
System.out.println("Circle is: " + r.circle());
}
}
class Rectangle{
private double width;
private double height;
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public double circle(){//求周长
return (width + height) * 2;
}
public double area(){//求面积
return width * height;
}
}
--------------------
5Five.java
public class Five {
public static void main(String[] args) {
AImpl a = new AImpl();
a.paint();
}
}
interface A {
public int method1(int x);
public int method2(int x, int y);
}
class AImpl implements A{
public int method1(int x) {
return (int)Math.pow(x, 5);
}
public int method2(int x, int y) {
return x y? x: y;
}
public void paint(){
int result1 = method1(2);
int result2 = method2(2, 8);
System.out.println("method1(2) = " + result1);
System.out.println("method2(2, 8) = " + result2);
}
}
-----------------------------测试
method1(2) = 32
method2(2, 8) = 8
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款