本文目录一览:
- 1、求程序员帮忙写个Java代码,因为今天我有事没时间做,明天要交作业,谢谢了
- 2、Java作业求帮助 编写一个Java程序,在程序中定义一个PersonB类,定义一个P
- 3、1、编写一个Application程序【java上机作业,要完整代码,急求!!!!!!!!!!】
- 4、JAVA作业求助
求程序员帮忙写个Java代码,因为今天我有事没时间做,明天要交作业,谢谢了
代码如下,随便附一句,一定要看写的源码,我已经尽量马马虎虎的写了,你更容易看懂。
public class Test {
// 第八题
public static final int NUM = 100;
public static final double GOOD = 99.99;
public static final String CLASSNAME = “Test.Class”;
public static final long MAX = 9999999;
public static void main(String[] args) {
// 第一题
byte byte1 = 1;
short short1 = 1;
int int1 = 1;
long long1 = 1;
float float1 = 1;
double double1 = 1.0;
System.out.println(“byte1 – ” + byte1);
System.out.println(“short1 – ” + short1);
System.out.println(“int1 – ” + int1);
System.out.println(“long1 – ” + long1);
System.out.println(“float1 – ” + float1);
System.out.println(“double1 – ” + double1);
// 第二题
String name;
char sex;
int age;
boolean isMember;
// 第三题
int score1;
double score2 = 98.5;
// 第四题
double f1 = 10.1, f2 = 34.2;
System.out.println(“f1,f2的和:” + (f1 + f2));
System.out.println(“f1,f2的差:” + (f1 – f2));
System.out.println(“f1,f2的积:” + (f1 * f2));
System.out.println(“f1,f2的商:” + (f1 / f2));
// 第五题
int f3 = 5;
double f4 = 45.6;
System.out.println(“f3,f4的和:” + (f3 + f4));
System.out.println(“f3,f4的差:” + (f3 – f4));
System.out.println(“f3,f4的积:” + (f3 * f4));
System.out.println(“f3,f4的商:” + (f3 / f4));
// 第六题
int A = 65;
char a = (char) A;
System.out.println(“整型互转char:” + a);
// 第七题
double timor = 123.456789;
int x = Integer
.parseInt(new java.text.DecimalFormat(“0”).format(timor));// 四舍五入
System.out.println(“double – int :” + x);
// 第八题(定义在最开始)
System.out.println(“常量NUM的值: ” + NUM);
System.out.println(“常量GOOD的值: ” + GOOD);
System.out.println(“常量CLASSNAME的值: ” + CLASSNAME);
System.out.println(“常量MAX的值: ” + MAX);
// 第九题(自定义商品类)
class Goods {
private String name;
private double price;
private int count;
private double total;
public Goods(String name, double price, int count) {
this.name = name;
this.price = price;
this.count = count;
}
public void print() {
total = price * count;
System.out.println(“商品名 价格 数量 总价”);
System.out.println(name + ” ” + price + ” ” + count + ” “
+ total);
}
}
Goods goods = new Goods(“苹果”, 2, 10);
goods.print();
// 第十题
double pi = 3.14, r, d;
r = 4;
d = 2 * r;
System.out.println(“圆的周长: ” + (pi * d));
System.out.println(“圆的面积: ” + (pi * r * r));
// 第十一题
String qqname = “1234567890”;
String qqpassword = “asd!#@#$%66”;
Date birth = new Date(2014, 5, 1);
boolean isVIP = false;
char sex1 = ‘男’;
StringBuilder personInfo = new StringBuilder();
personInfo.append(“我是一个快乐的骚年”);
personInfo
.append(“然后a!#$%^*asdasdasdasdsa9d87a9s8d79asdjidauisdhausdihiasd”);
// 第十二题
class Swaper {
public void change(int num1, int num2) {
int temp = num1;
num1 = num2;
num2 = temp;
System.out.printf(“a=%d,b=%d\n”, num1, num2);
}
}
int a1 = 2;
int b1 = 5;
Swaper swaper = new Swaper();
swaper.change(a1, b1);
}
}
Java作业求帮助 编写一个Java程序,在程序中定义一个PersonB类,定义一个P
class PersonB
{
String name ;
int age;
public PersonB()
{
System.out.println(“PersonB()被调用”);
}
public PersonB(String newName)
{
name = newName;
System.out.println(“PersonB(String newName)被调用”);
}
public void introduce( )
{
System.out.println(“我是”+name+”,今年”+age+”岁”);
}
}
class StudentB extends PersonB
{
// 【代码1】 //创建一个参数为空的StudentB类构造方法,能显示“StudentB() 被调用”
public StudentB(){
System.out.println(“StudentB() 被调用”);
}
public StudentB(String newName,int newAge)
{
// 【代码2】 //调用父类的public PersonB(String newName)类构造方法,传入newName参数,提示使用关键词super进行调用
super(newName);
// 【代码3】 //将newAge赋值给age属性
super.age = newAge;
}
}
class C2
{
public static void main(String []args)
{
StudentB s1 = new StudentB();
StudentB s2 = new StudentB(“张三”,19);
// 【代码4】 //调用s2的 introduce方法
s2.introduce();
}
}
纯手打,采纳采纳!!!!!!!!11
1、编写一个Application程序【java上机作业,要完整代码,急求!!!!!!!!!!】
第一题:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class RadioTest extends JFrame{
private JRadioButton jrb1;
private JRadioButton jrb2;
private JLabel jlbl;
private JPanel jp;
private JButton jbtn;
private String jlstr;
private ButtonGroup bg;
public RadioTest(){
jlstr = “你选择的是:”;
this.setTitle(“实现单选按钮的效果”);
jrb1 = new JRadioButton(“男”);
jrb2 = new JRadioButton(“女”);
bg = new ButtonGroup();
bg.add(jrb1);
bg.add(jrb2);
jlbl = new JLabel(jlstr);
jbtn = new JButton(“退出”);
jbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(1);
}
});
jrb1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jrb1){
jlbl.setText(jlstr+jrb1.getText());
}
}
});
jrb2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jrb2){
jlbl.setText(jlstr+jrb2.getText());
}
}
});
jp = new JPanel();
jp.add(jrb1);
jp.add(jrb2);
jp.add(jlbl);
jp.add(jbtn);
this.add(jp);
this.setBounds(300, 300, 230, 200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
RadioTest rt = new RadioTest();
}
}
JAVA作业求助
做个练习,仅供参考。
代码如下:
package com.hello.algorithm;
import java.util.Arrays;
import java.util.Scanner;
public class InsertSort {
public static void main(String[] args) {
// 创建一个数组存储成绩,需要指定长度
int[] scores = new int[6]; //假设存储6个成绩:100 99 85 82 63 60
int index = 0;
while(index scores.length) {
// 控制台接收成绩
System.out.print(“请输入成绩(100 99 85 82 63 60):”);
Scanner scanner = new Scanner(System.in); // 随机插入成绩
int s = scanner.nextInt();
// 将接收的成绩与数组中的所有成绩进行比较,按照从大到小的规则,找到插入位置,然后插入数组
int insertPos = 0;
int temp = 0;
int temp2 = 0;
// 第一遍遍历数组找到插入位置
for(int i = 0; i scores.length; i++){
if(s scores[i]){
insertPos = i;
temp = scores[i];
scores[i] = s;
break;
}
}
// 第二遍遍历从插入位置整体后移
for(int i = 0; i scores.length; i++){
// 插入位置后面的元素整体后移
if(i insertPos){
temp2 = scores[i];
scores[i] = temp;
temp = temp2;
}
}
// 打印该成绩的插入位置以及打印整个数组
System.out.println(“插入成绩的下标:” + insertPos);
System.out.println(Arrays.toString(scores));
index++;
}
}
}
运行结果如下:
请输入成绩(100 99 85 82 63 60):63
插入成绩的下标:0
[63, 0, 0, 0, 0, 0]
请输入成绩(100 99 85 82 63 60):60
插入成绩的下标:1
[63, 60, 0, 0, 0, 0]
请输入成绩(100 99 85 82 63 60):82
插入成绩的下标:0
[82, 63, 60, 0, 0, 0]
请输入成绩(100 99 85 82 63 60):99
插入成绩的下标:0
[99, 82, 63, 60, 0, 0]
请输入成绩(100 99 85 82 63 60):85
插入成绩的下标:1
[99, 85, 82, 63, 60, 0]
请输入成绩(100 99 85 82 63 60):100
插入成绩的下标:0
[100, 99, 85, 82, 63, 60]
Process finished with exit code 0
原创文章,作者:NHYKP,如若转载,请注明出处:https://www.506064.com/n/315895.html