java第一次作業參考代碼(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/zh-hk/n/315895.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
NHYKP的頭像NHYKP
上一篇 2025-01-09 12:14
下一篇 2025-01-09 12:14

相關推薦

  • Java JsonPath 效率優化指南

    本篇文章將深入探討Java JsonPath的效率問題,並提供一些優化方案。 一、JsonPath 簡介 JsonPath是一個可用於從JSON數據中獲取信息的庫。它提供了一種DS…

    編程 2025-04-29
  • java client.getacsresponse 編譯報錯解決方法

    java client.getacsresponse 編譯報錯是Java編程過程中常見的錯誤,常見的原因是代碼的語法錯誤、類庫依賴問題和編譯環境的配置問題。下面將從多個方面進行分析…

    編程 2025-04-29
  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • Java Bean加載過程

    Java Bean加載過程涉及到類加載器、反射機制和Java虛擬機的執行過程。在本文中,將從這三個方面詳細闡述Java Bean加載的過程。 一、類加載器 類加載器是Java虛擬機…

    編程 2025-04-29
  • Python字符串寬度不限制怎麼打代碼

    本文將為大家詳細介紹Python字符串寬度不限制時如何打代碼的幾個方面。 一、保持代碼風格的統一 在Python字符串寬度不限制的情況下,我們可以寫出很長很長的一行代碼。但是,為了…

    編程 2025-04-29
  • Java騰訊雲音視頻對接

    本文旨在從多個方面詳細闡述Java騰訊雲音視頻對接,提供完整的代碼示例。 一、騰訊雲音視頻介紹 騰訊雲音視頻服務(Cloud Tencent Real-Time Communica…

    編程 2025-04-29
  • Java Milvus SearchParam withoutFields用法介紹

    本文將詳細介紹Java Milvus SearchParam withoutFields的相關知識和用法。 一、什麼是Java Milvus SearchParam without…

    編程 2025-04-29
  • Python第一章題庫

    本篇文章將從以下幾個方面對Python第一章題庫進行詳細的闡述,包括基本語法、數據類型、控制語句、函數和模塊等方面。 一、基本語法 Python是一門簡單易學、功能強大的編程語言,…

    編程 2025-04-29
  • Python基礎代碼用法介紹

    本文將從多個方面對Python基礎代碼進行解析和詳細闡述,力求讓讀者深刻理解Python基礎代碼。通過本文的學習,相信大家對Python的學習和應用會更加輕鬆和高效。 一、變量和數…

    編程 2025-04-29
  • Java 8中某一周的周一

    Java 8是Java語言中的一個版本,於2014年3月18日發佈。本文將從多個方面對Java 8中某一周的周一進行詳細的闡述。 一、數組處理 Java 8新特性之一是Stream…

    編程 2025-04-29

發表回復

登錄後才能評論