本文目录一览:
- 1、简单的java程序题
- 2、JAVA程序题?
- 3、5道简单的JAVA编程题(高分悬赏)
- 4、有关java编程题目?
- 5、Java编程题编写一个Java Application程序包含Person类、Student(学?
- 6、有几个java编程的题各位好心人有时间的能帮忙写下吗?
简单的java程序题
public
class
student{
private
string
stuid;
private
string
stuname;
private
char
stusex;
private
int
stuage;
/**
*以下是各属性的getter/setter方法
*/
public
void
setstuid(string
stuid){
this.stuid=stuid;
}
public
string
getstuid(){
return
stuid;
}
public
void
setstuname(string
stuname){
this.stuname=stuname;
}
public
string
getstuname(){
return
stuname;
}
public
void
setstusex(char
stusex){
this.stusex=stusex;
}
public
char
getstusex(){
return
stusex;
}
public
void
setstuage(int
stuage){
this.stuage=stuage;
}
public
int
getstuage(){
return
stuage;
}
/**
*构造方法,构造学生信息
*/
public
student(string
stuid,string
stuname,char
stusex,int
stuage){
this.stuid=stuid;
this.stuname=stuname;
this.stusex=stusex;
this.stuage=stuage;
}
public
string
tostring(){//覆盖该类的tostring()方法
stringbuffer
buff=new
stringbuffer();
buff.append("学号:"+stuid);
buff.append("\n姓名:"+stuname);
buff.append("\n性别:"+stusex);
buff.append("\n年龄:"+stuage);
return
buff.tostring();
}
public
static
void
main(string[]
args){
student
stu=new
student("1000","zhangsan",'男',18);
system.out.println
(stu);//打印学生信息
system.out.println
("--修改姓名结果--");
stu.setstuname("lisi");
system.out.println
(stu);
}
}
JAVA程序题?
我的思路:
1.定义一个开关的接口(ISWitcher),用于设定开关的功能
2.定义开关类实现开关接口的功能
3.定义电器类,所有电器的父类
4.对电灯,投影仪,风扇等电器进行定义
5.进行测试
5道简单的JAVA编程题(高分悬赏)
很详细的帮你写下,呵呵,所以要给分哦!
1、
(1)源程序如下:
public class One {
public static void main(String[] args) {
String name = "张三";
int age = 23;
char sex = '男';
String myclass = "某某专业2班";
System.out.println("姓名:" + name);
System.out.println("姓名:" + age);
System.out.println("姓名:" + sex);
System.out.println("姓名:" + myclass);
}
}
(2)
编写完程序的后缀名是.java,如本题,文件名就是One.java。
开始\运行\cmd,进入“命令提示符窗口”,然后用javac编译器编译.java文件,语句:javac One.java。
(3)
编译成功后,生成的文件名后缀是.class,叫做字节码文件。再用java解释器来运行改程序,语句:java One
2、编写程序,输出1到100间的所有偶数
(1)for语句
public class Two1 {
public static void main(String[] args) {
for(int i=2;i=100;i+=2)
System.out.println(i);
}
}
(2)while语句
public class Two2 {
public static void main(String[] args) {
int i = 2;
while (i = 100) {
System.out.println(i);
i += 2;
}
}
}
(3)do…while语句
public class Two3 {
public static void main(String[] args) {
int i = 2;
do {
System.out.println(i);
i += 2;
}while(i=100);
}
}
3、编写程序,从10个数当中找出最大值。
(1)for循环
import java.util.*;
public class Three1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
for (int i = 0; i 10; i++) {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max number)
max = number;
}
System.out.println("最大值:" + max);
}
}
(2)while语句
import java.util.*;
public class Three2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
while (i 10) {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max number)
max = number;
i++;
}
System.out.println("最大值:" + max);
}
}
(3)do…while语句
import java.util.*;
public class Three3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
do {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max number)
max = number;
i++;
}while(i10);
System.out.println("最大值:" + max);
}
}
4、编写程序,计算从1到100之间的奇数之和。
(1)for循环
public class Four1 {
public static void main(String[] args) {
int sum=0;
for(int i = 1;i=100;i+=2){
sum+=i;
}
System.out.println("1~100间奇数和:" + sum);
}
}
(2)while语句
public class Four2 {
public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i = 100) {
sum += i;
i += 2;
}
System.out.println("1~100间奇数和:" + sum);
}
}
(3)do…while语句
public class Four3 {
public static void main(String[] args) {
int sum = 0;
int i = 1;
do {
sum += i;
i += 2;
} while (i = 100);
System.out.println("1~100间奇数和:" + sum);
}
}
5、
(1)什么是类的继承?什么是父类?什么是子类?举例说明。
继承:是面向对象软件技术当中的一个概念。如果一个类A继承自另一个类B,就把这个A称为"B的子类",而把B称为"A的父类"。继承可以使得子类具有父类的各种属性和方法,而不需要再次编写相同的代码。在令子类继承父类的同时,可以重新定义某些属性,并重写某些方法,即覆盖父类的原有属性和方法,使其获得与父类不同的功能。另外,为子类追加新的属性和方法也是常见的做法。继承需要关键字extends。举例:
class A{}
class B extends A{}
//成员我就不写了,本例中,A是父类,B是子类。
(2)编写一个继承的程序。
class Person {
public String name;
public int age;
public char sex;
public Person(String n, int a, char s) {
name = n;
age = a;
sex = s;
}
public void output1() {
System.out.println("姓名:" + name + "\n年龄:" + age + "\n性别:" + sex);
}
}
class StudentPerson extends Person {
String school, department, subject, myclass;
public StudentPerson(String sc, String d, String su, String m, String n,
int a, char s) {
super(n, a, s);
school = sc;
department = d;
subject = su;
myclass = m;
}
public void output2() {
super.output1();
System.out.println("学校:" + school + "\n系别:" + department + "\n专业:"
+ subject + "\n班级:" + myclass);
}
}
public class Five2 {
public static void main(String[] args) {
StudentPerson StudentPersonDemo = new StudentPerson("某某大学", "某某系别",
" 某专业", "某某班级", " 张三", 23, '男');
StudentPersonDemo.output2();
}
}
有关java编程题目?
按照题目要求编写的圆,圆锥和测试类的Java程序如下
Test.java文件内容如下
class Circle{
private double r;
private String color;
public Circle(double r){
this.r=r;
}
public double area(){
return Math.PI*r*r;
}
public double perimeter(){
return Math.PI*2*r;
}
public double getR(){
return this.r;
}
public void setR(double r){
this.r=r;
}
public String getColor(){
return this.color;
}
public void setColor(String color){
this.color=color;
}
public String toString(){
return "圆的半径为"+r+",颜色为"+color;
}
}
class Cone{
private Circle c;
private double h;
private String color;
public Cone(Circle c,double h){
this.c=c;
this.h=h;
}
public double volume(){
return 1.0/3*c.area()*h;
}
public Circle getCircle(){
return this.c;
}
public void setCircle(Circle c){
this.c=c;
}
public double getH(){
return this.h;
}
public void setH(double h){
this.h=h;
}
public String getColor(){
return this.color;
}
public void setColor(String color){
this.color=color;
}
public String toString(){
return "圆锥的底面积为"+c.area()+",高为"+h+",颜色为"+color;
}
}
public class Test{
public static void main(String[] args){
Circle circle1=new Circle(2.5);
circle1.setColor("红色");
System.out.println(circle1.toString());
System.out.println("圆的面积为"+circle1.area());
System.out.println("圆的周长为"+circle1.perimeter());
Cone circlar1=new Cone(circle1,2.7);
circlar1.setColor("蓝色");
System.out.println(circlar1.toString());
System.out.println("圆锥的体积为"+circlar1.volume());
}
}
Java编程题编写一个Java Application程序包含Person类、Student(学?
public class Person {
private String name;//姓名
private String sex;//性别
public void sayHello() {
System.out.println("姓名:" + name);
System.out.println("性别:" + sex);
}
public Person() {
}
public Person(String name, String sex) {
this.name = name;
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
public class Student extends Person {
private String num;//学号
private String school;//学校
public void sayHello() {
super.sayHello();
System.out.println("学号:" + num);
System.out.println("学校:" + school);
}
public Student(String num, String school) {
this.num = num;
this.school = school;
}
public Student(String name, String sex, String num, String school) {
super(name, sex);
this.num = num;
this.school = school;
}
public Student() {
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
}
public class Test {
public static void main(String[] args) {
Student stu1 = new Student();
stu1.setName("张三");
stu1.setSex("男");
stu1.setNum("20211225001");
stu1.setSchool("北京大学");
Student stu2 = new Student("20211225002", "北京大学");
stu2.setName("李四");
stu2.setSex("男");
Student stu3 = new Student("王五", "女", "20211225003", "清华大学");
Person person1 = new Person();
person1.setName("赵六");
person1.setSex("女");
Person person2 = new Person("孙七", "女");
stu1.sayHello();
stu2.sayHello();
stu3.sayHello();
person1.sayHello();
person2.sayHello();
}
}
有几个java编程的题各位好心人有时间的能帮忙写下吗?
没那么多时间,帮着写个第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; ia.length; i++ ){
sum += a[i];
if(i == 0){
min = a[i];
}else{
if(a[i] min){
min = a[i];
}
}
}
System.out.println("当前数组中最小的元素值是: "+min);
System.out.println("当前数组和是: "+sum);