package comxkparent;
public class Shape {
public Shape() {
}
}
package comxksub;
import comxkparentShape;
//正方形
public class Square extends Shape implements Computer{
protected double width;
protected double length;
public Square() {
width=0;
length=0;
}
public Square(double width,double length) {
thislength=length;
thiswidth=width;
}
public double computeArea() {
return lengthwidth;
}
public double computePerimeter() {
return length2+width2;
}
public double getWidth() {
return thiswidth;
}
public void setWidth(double width) {
thiswidth=width;
}
public double getLength() {
return thislength;
}
public void setLength(double length) {
thislength=length;
}
}
package comxksub;
//棱形
public class Prismatic extends Square {
private double height;
public Prismatic() {
super();
thisheight=0;
}
public Prismatic(double width,double length,double height) {
super(width,length);
thisheight=height;
}
public double getHeight() {
return thisheight;
}
public void setHeight(double height) {
thisheight=height;
}
@Override
public double computeArea() {
return thiswidththisheight;
}
@Override
public double computePerimeter() {
return supercomputePerimeter();
}
}
package comxksub;
//接口
public interface Computer {
public double computeArea();
public double computePerimeter();
}
3改错题
仔细阅读以下程序,改正程序中的错误(星号下面的语句),使程序能输出正确的结果。
注意:
(1)不改动程序的结构,不得增行或删行。
(2)不能更改定义类和方法的访问修饰符。
//Java3java
public class Java3{
String xh;
String name;
int score;
/found/
public void Java3(String num, String xm, int sco)
{
xh = num;
name = xm;
score = sco;
}
/found/
public boolean changeInfo(int sco, String num)
{
if(score== sco&&xh==num){
result = true;
}
else
result = false;
}
public static void main(String args[]){
Java3 java3=new Java3("090101","Tom",100);
if(java3changeInfo("090101",100))
Systemoutprintln("score no change!");
else
Systemoutprintln("score change!");
}
你的题有很多错误,我给你改了一下。
1设变量i和j的定义如下,试分别计算下列表达式的值:
int i=1; double d=10;
1题 35/4 [8]
2题 46%9+44-2 [15]
3题 45+43%5(233%2)[48]
4题 45+4550%i-- [45]
5题 45+4550%(i--) [45]
6题 153+(++d) [65]
7题 153+d++ [55]
8题 i+=3/i+3 [7]
程序阅读题
1给定如下代码,写出程序运行结果
class Example{
public static void main(String arges[]){
int i=0;
do{
Systemoutprintln("doing it for i is:"+i);
}while(--i>0);
Systemoutprintln("finish");
}
}
结果如下:
doing it for i is:0
finish
2 阅读程序段写出执行结果
for(int k=1;k<=5;k++){
if(k>4)break;
Systemoutprintln("k="+k);
}
结果:
k=1
k=2
k=3
k=4
3试写出下列程序段循环的运行结果
int i=1;
while(i<10)
if(i++%2==0)
Systemoutprintln(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;
}
Systemoutprintln("sum = " + sum);
}
求100之内的所有“完数”。完数是指等于它的因子和的数。例如:6=1+2+3,6=123,则6是一个完数
public class wanshu{
public static void main(String[] args) {
for(int i = 1; i <= 100; i++) {
if(fun(i)) {
Systemoutprintln(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;
}
}
public class Car{
private String carNum;
private String carColor;
private int carSpeed;
public Car(String carNum,String carColor,int carSpeed){ //构造方法
thiscarNum=carNum;
thiscarColor=carColor;
thiscarSpeed=carSpeed;
}
public void addSpeed(int num){ //加速方法
thiscarSpeed+=num;
}
public void subSpeed(int num){ //减速方法
if(thiscarSpeed-num>=0){
thiscarSpeed-=num;
}
}
}
没那么多时间,帮着写个第1题吧
// 编写求一个整数数组A[10,15,12,9,7]中最小元素min和元素之和sum的
int [] a = {10,15,15,9,7};
// 最小元素
int min=0;
// 数组和
int sum=0;
for(int i=0; i<alength; i++ ){
sum += a[i];
if(i == 0){
min = a[i];
}else{
if(a[i] < min){
min = a[i];
}
}
}
Systemoutprintln("当前数组中最小的元素值是: "+min);
Systemoutprintln("当前数组和是: "+sum);
import javatextParseException;
import javatextSimpleDateFormat;
import javautilDate;
class Student {
private String id;
private String name;
private boolean isMale;
private Date birth;
public Student() {
super();
}
public Student(String id, String name, boolean isMale, Date birth) {
super();
thisid = id;
thisname = name;
thisisMale = isMale;
thisbirth = birth;
}
public String getId() {
return id;
}
public void setId(String id) {
thisid = id;
}
public String getName() {
return name;
}
public void setName(String name) {
thisname = name;
}
public boolean isMale() {
return isMale;
}
public void setMale(boolean isMale) {
thisisMale = isMale;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
thisbirth = birth;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", isMale=" + isMale + ", birth=" + birth + "]";
}
}
public class StudentTest {
public static void main(String[] args) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
Student stu = new Student("00001", "Tom", true, dateFormatparse("2000-01-01"));
Systemoutprintln(stu);
}
}
1
import javautilScanner;
public class Cube{
private double len; //定义边长
//获得边长
public double getLen() {
return len;
}
//赋值边长
public void setLen(double len) {
thislen = len;
}
//计算表面积
public double getArea(double len){
return lenlen6;
}
//计算体积
public double getVolume(double len){
return lenlenlen;
}
public static void main(String[] args) {
Cube c = new Cube();
Systemoutprint("请输入边长:");
csetLen(new Scanner(Systemin)nextDouble());
Systemoutprintln("边长为:"+cgetLen()+"的立方体,表面积是:"+cgetArea(cgetLen())
+",体积是:"+cgetVolume(cgetLen())+"。");
}
}
2
import javautilScanner;
public class Student{
private String stuName; //定义姓名
private double chineseScore; //定义语文成绩
private double mathScore; //定义数学成绩
private double computerScore;
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
thisstuName = stuName;
}
public double getChineseScore() {
return chineseScore;
}
public void setChineseScore(double chineseScore) {
thischineseScore = chineseScore;
}
public double getMathScore() {
return mathScore;
}
public void setMathScore(double mathScore) {
thismathScore = mathScore;
}
public double getComputerScore() {
return computerScore;
}
public void setComputerScore(double computerScore) {
thiscomputerScore = computerScore;
}
public double avg(double chineseScore,double mathScore,double computerScore){
return (chineseScore+mathScore+computerScore)10/3;
}
public static void main(String[] args) {
Student stu = new Student();
Systemoutprint("请输入学生姓名:");
stusetStuName(new Scanner(Systemin)next());
Systemoutprint("请输入该学生语文成绩:");
stusetChineseScore(new Scanner(Systemin)nextDouble());
Systemoutprint("请输入该学生数学成绩:");
stusetMathScore(new Scanner(Systemin)nextDouble());
Systemoutprint("请输入该学生计算机成绩:");
stusetComputerScore(new Scanner(Systemin)nextDouble());
Systemoutprintln(stugetStuName()+"学生的平均成绩是"+
stuavg(stugetChineseScore(), stugetMathScore(), stugetComputerScore()));
}
}
1、package nettest;
public class TestArray
{
int a[]={12,34,5,7,9,10};
public int max()
{
int j = a[1];
for(int i :a)
{
if(i > j)
{
j = i ;
}
}
return j;
}
public long avrage()
{
long j = 0l;
for(int i :a)
{
j = j + i;
}
return j/alength;
}
}
2、package nettest;
public class Person
{
String name;
int age;
Person(String name,int age)
{
thisname = name;
thisage = age;
}
public void printInfo()
{
Systemoutprintln("name = "+thisname+" age = "+thisage);
}
}
package nettest;
public class Student extends Person
{
String studentId;
Student(String name, int age)
{
super(name, age);
}
Student(String name, int age,String studentId)
{
super(name, age);
thisstudentId = studentId;
}
public void printInfo()
{
Systemoutprintln("name = "+thisname+" age = "+thisage+" StudentId =" + thisstudentId);
}
}
3、package nettest;
public class TestPrint
{
public static void main(String[] args)
{
for (int i = 1; i<10;i++)
{
for(int j = 0; j<i;j++)
{
Systemoutprint("");
}
Systemoutprintln();
}
}
}
以上就是关于JAVA程序设计题,请大神帮忙,很简单,是一道基础题。全部的内容,包括:JAVA程序设计题,请大神帮忙,很简单,是一道基础题。、速求java程序设计基础,改错题题目(例题之类的)、JAVA程序设计题(很简单的)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)