导航:首页 > 编程语言 > java基础综合编程题

java基础综合编程题

发布时间:2022-07-05 18:21:11

java 基础编程题。题目如下:

importjava.util.Scanner;

publicclassTest{
publicstaticString[]input(){
Scannersc=newScanner(System.in);
String[]a=newString[5];
System.out.println("输入名字:");
for(inti=0;i<a.length;i++){
a[i]=sc.nextLine();
}
returna;
}
publicstaticvoidmain(String[]args){
String[]b=input();
intran=(int)(Math.random()*b.length);
System.out.println("随机输出一个名字:"+b[ran]);
}
}

Ⅱ 大家帮忙做下这几道java基础编程题(谢了)

//-_-!~

import java.util.*;

public class TestOne {

static Scanner san = new Scanner(System.in);

public static void main(String[] args) {
String [] ps = new String[3];
System.out.print("Input name: ");
ps[0] = san.next();
System.out.print("Input sex: ");
ps[1] = san.next();
System.out.print("Input age: ");
ps[2] = san.next();
for(String s: ps) {
System.out.print(s + " ");
}
System.out.println("\n------------------------------------");
System.out.print("Input int: ");
int i = san.nextInt();
System.out.print("Input float: ");
float f = san.nextFloat();
System.out.print("Bigger one: " + TestOne.numberCompare(i, f));
System.out.println("\n-------------------------------------");
Employee e = new Employee(25, "XP1254", "TIGER", true);
System.out.println(e);

}

//重载
public static String numberCompare (int i, float f){
if(f - i > 0) {
return f +"";
} else {
return i +"";
}
}
//重载
public static String numberCompare (float f, int i){
if(f - i > 0) {
return f +"";
} else {
return i +"";
}
}
}

class Employee{
private String id;//string型代表员工ID号;
private String name;//:string型代表姓名;
private int age;//:int型代表年龄;
private boolean sex;//:boolen型代表性别(其中 true代表男,false代表女)

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public boolean isSex() {
return sex;
}

public void setSex(boolean sex) {
this.sex = sex;
}

public Employee(){
this(0, null, null, false);
}

public Employee(int age, String id, String name, boolean sex) {
this.age = age;
this.id = id;
this.name = name;
this.sex = sex;
}

public String toString(){
return this.getName() + ": " + this.getAge();
}

}

Ⅲ 用JAVA编程 类与对象的基础题

class Phone{
private String phonenumber;
public void setPhonenumber(String phonenumber){
this.phonenumber=phonenumber;
}
public String getPhonenumber(){
return phonenumber;
}
public void recCall(){
System.out.println("接到一个电话");
}
public void telCall(){
System.out.println("拨出一个电话");
}
}class Fixedphone extends Phone{
private String phonenumber;//号码是私有,设置为private,不可继承
public void recCall(){
System.out.println("以"+this.phonenumber+"呼出了一个电话"); //重载了父类的recCall
}
}class Cordlessphone extends Fixedphone{
private String phonenumber;
public void info(){
System.out.println("这是无绳电话的信息");
}
}interface Moveable{
public void moveinfo();
}class Mobilephone extends Phone implements Moveable{
private String phonenumber;
public void moveinfo(){
System.out.println("我实现了可移动性");
}
}public class PhoneTest{
public static void main(String a[]){
Phone[] p=new Phone[5];
Phone p1=new Phone();
p1.setPhonenumber("123456789");
p[0]=p1;
Phone p2=new Phone();
p2.setPhonenumber("987654321");
p[1]=p2;
Mobilephone mp=new Mobilephone();
mp.setPhonenumber("11111");
p[2]=mp;
Fixedphone fp=new Fixedphone();
fp.setPhonenumber("22222");
p[3]=fp;
Cordlessphone cp=new Cordlessphone();
cp.setPhonenumber("33333");
p[4]=cp;

for(int i=0;i<p.length;i++){
System.out.println(p[i].getPhonenumber());
} p[4]=p[1];
System.out.println(p[4].getPhonenumber());

}} 写的不是很好,希望对你有帮助噶

Ⅳ java入门编程题:某班有十位同学,请顺序输入十位同学的学号,保存在数组中,并输出所有同学的学号

import java.util.Scanner;

public class Students {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] students=new String[10];
String No=null;
for (int i = 0; i <10 ; i++) {
System.out.println("请输入学号:");
No=in.next();
students[i]=No;
}
System.out.println("学号是:");
for (String a:students) {
System.out.print(a+" ");
}
}
}

Ⅳ JAVA基础编程题~

public class student{
private String name;
private int age;

public student(String name,int age){ //student的带有String,int带参数的构造函数
this.name = name;
this.age = age; //把传进来的参数赋值给创建出来的类的对象
}

public static void main(String[] args){
student s = new student("zhangsan",18); //调用student的构造函数创 造一个对象s
System.out.println("姓名:"+s.name+"年龄:"+s.age);//调用对象的属性就用s.name s.age!
}
}
----------------------------------------------------------------------

public class Student {
static String name;//设定String类型的静态变量name
static int age;//设定int类型的静态变量age

public static void main(String[] args){//main为主方法,运行从main开始
name="zhangsan";//给name赋值zhangsan
age=18;//给age赋值18
System.out.println("该学生的名字为"+name+"年龄为:"+age);//输出name和age
}
}
static 修饰的属性和方法只属于这个类本身,而不属于这个类所创建出来的对象,所以可以直接写name,age 而不用像上面那种要先创建个类的对象出来 !

Ⅵ 关于JAVA的基础编程题

顶楼上,还有题目很烂,前后类型要一直,否则会丢精度,就拿工资来说吧
定义float型,最后计算返回int型,还有就是计算工资时,根本不需要传参数,因为这个类已经有足够的数据支持了,不知道getDecMoney(int day)方法中day的有什么意义
public class Employee {
int id;
byte sex;
String name;
String ty;
float salary;
int holidays;
Employee(int id,byte sex,String name,String ty,float salary,int holidays)
{
this.id=id;
this.sex=sex;
this.name=name;
this.ty=ty;
this.salary=salary;
this.holidays=holidays;

}

public void dispaly()
{
System.out.println("员工姓名:"+this.name);
if(this.sex==(byte)0)
System.out.println("员工性别:男");
else
System.out.println("员工性别:女");
System.out.println("员工职务:"+this.ty);

}

public int getDecMoney(int day)
{
if(day<=3)
this.salary-=30*day;
else
this.salary-=50*day;
return (int)this.salary;

}

public static void main(String[] args)
{
Employee employee=new Employee(123,(byte) 0,"张三","科长",3000.0f,2);
employee.dispaly();
System.out.println("该员工本月工资:"+employee.getDecMoney(employee.holidays));

}
}

Ⅶ JAVA基础编程题

package com.qiu.swing.layoutDemo;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.JTextField;

/**
*
* @author Qiu
*
*/
public class TextDemo extends JFrame{

final JButton button_show = new JButton("显示");
final JButton button_clear = new JButton("显示");
final JTextField text = new JTextField();
final Container con = this.getContentPane();

public TextDemo() {
this.setTitle("HelloWorld!");
this.setSize(300, 160);
// 居中
this.setLocationRelativeTo(null);
this.setUndecorated(true); // 去掉窗口的装饰
this.setResizable(false);

this.getRootPane().setWindowDecorationStyle(
JRootPane.INFORMATION_DIALOG);// 采用指定的窗口装饰风格

// 文字居中
text.setSize(100, 20);

Box vbox = Box.createVerticalBox();
Box xbox0 = Box.createHorizontalBox();
xbox0.add(text);
xbox0.add(button_show);
xbox0.add(button_clear);
vbox.add(xbox0);
vbox.add(Box.createVerticalStrut(100));
con.setLayout(new BoxLayout(con, BoxLayout.X_AXIS));
con.add(vbox);

button_show.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText("HelloWorld");
}
});
button_clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText("");
}
});

}
public static void main(String[] args) {
TextDemo home = new TextDemo();
home.setVisible(true);
}
}

Ⅷ Java 基础编程题求解,不是很懂

第一种:方式借助于,while循环获取,提示输入内容获取输入值,然后判断如果余数为5结束循环。

int i = 0;
do{
System.out.println("请输入数据边界值:");
//获取输入数字
Scanner sc = new Scanner(System.in);
int s = sc.nextInt();

i = s%10;
if(i == 5){
System.out.println(s);
sc.close();
}

}while( i == 5 );

引入类:

Ⅸ 基础JAVA编程题 请高手作解

3.
public class c4_16 extends Applet
{ public void init()
{ double a=2,b=3;
double z1=Math.pow(a,b); //引用Math类的pow方法求a的b次方
double z2=Math.sqrt(9); //引用Math类的sqrt方法求9的平方根
System.out.print("z1="+z1);
System.out.print("\tz2="+z2);

}
}
6.
public class BB
{
static int sum;
void Sum50(int a)
{
int i=a;
sum=sum+i;
if(i>0)
{
a--;
Sum50(a);
}
}
public static void main(String args[])
{
BB b=new BB();
b.Sum50(50);
System.out.println(sum);
}
}

阅读全文

与java基础综合编程题相关的资料

热点内容
编译程序输入一个字符串 浏览:404
圆命令画法 浏览:305
如果给电脑e盘文件加密 浏览:801
javaswing项目 浏览:774
androidsdksetup 浏览:1003
pdf怎么设置中文 浏览:126
安卓手机用什么软件看伦敦金 浏览:964
魅族文件夹无名称 浏览:789
苏黎世无人机算法 浏览:872
核桃编程和小码王的融资 浏览:684
微积分教材pdf 浏览:725
写python给微信好友发消息 浏览:336
蚊帐自营米加密 浏览:420
学校推荐核桃编程 浏览:804
湖南农信app怎么导明细 浏览:473
福特abs编程 浏览:509
如何自学安卓手机 浏览:439
以太坊源码共识机制 浏览:912
单片机探测器 浏览:872
demo编程大赛作品怎么运行 浏览:52