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();
}
}
}
public static void main(String[] args) {
Scanner input = new Scanner(Systemin);
Systemoutprintln("请个输入三个数:");
int num1 = inputnextInt();
int num2 = inputnextInt();
int num3 = inputnextInt();
int numMax = 0;
numMax = num1>num2num1:num2;
numMax = numMax>num3numMax:num3;
Systemoutprintln("三个数中最大的数字为:"+numMax);
}
哈哈 我昨天刚做了这个作业 你够幸运
import javaawt;
import javaawtevent;
import javaxswing;
import javamath;
public class Homework10_3 {
public static void main(String args[]){
MathWindow win=new MathWindow();
}
}
class MathWindow extends JFrame{
JTextField text1,text2,text3;
JPanel ps,pn;
MathWindow(){
text1=new JTextField(10);
text2=new JTextField(10);
text3=new JTextField(10);
JButton button1,button2,button3,button4;
button1=new JButton("加");
button2=new JButton("减");
button3=new JButton("乘");
button4=new JButton("除");
ps=new JPanel();
pn=new JPanel();
pnadd(text1);
pnadd(text2);
pnadd(text3);
psadd(button1);
psadd(button2);
psadd(button3);
psadd(button4);
add(pn,BorderLayoutCENTER);
add(ps,BorderLayoutSOUTH);
setBounds(100,100,370,150);
setVisible(true);
validate();
button1addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1getText();
String s2=text2getText();
try{ BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n2=n1add(n2);
text3setText(n2toString());
}
catch(NumberFormatException ee){
text3setText("请输入数字字符");
text1setText(null);
text2setText(null);
}
}
});
button2addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1getText();
String s2=text2getText();
try{ BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n2=n1subtract(n2);
text3setText(n2toString());
}
catch(NumberFormatException ee){
text3setText("请输入数字字符");
text1setText(null);
text2setText(null);
}
}
});
button3addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1getText();
String s2=text2getText();
try{ BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n2=n1multiply(n2);
text3setText(n2toString());
}
catch(NumberFormatException ee){
text3setText("请输入数字字符");
text1setText(null);
text2setText(null);
}
}
});
button4addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1getText();
String s2=text2getText();
try{ BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
if(n2toString()=="0"){
text3setText("除数不能为0");
}
else
{
n2=n1divide(n2);
text3setText(n2toString());
}
}
catch(NumberFormatException ee){
text3setText("请输入数字字符");
text1setText(null);
text2setText(null);
}
}
});
setDefaultCloseOperation(JFrameDISPOSE_ON_CLOSE);
}
}
1Object
2final
3Object
4this,super
一、读程序写结果
1100
2
数组a:123456,200,300
数组b:123456,200,300
数组b的长度: 3
3
a=10
b=30
c=60
以上就是关于java面向对象程序设计练习题 求解答全部的内容,包括:java面向对象程序设计练习题 求解答、Java程序设计的几道题、JAVA程序设计题!请高手帮我解答!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)