当前位置:首页 » 编程软件 » java编程基础题

java编程基础题

发布时间: 2022-04-07 17:58:04

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 );

引入类:

㈡ 跪求50道java基础编程题目(含答案)。

楼主 我真怀疑你的人品,你要知道你现在是在求别人,感觉好像别人在求你一样,不是我说你你提出这样没水准的问题真的很蛋疼很蛋疼,网络知道有你这样的人真是一大祸害

㈢ java入门编程题

importjava.util.Scanner;
publicclassProgram{
publicstaticvoidmain(String[]args){
Scanners=newScanner(System.in);
System.out.println("请输入华氏温度:");
intF=s.nextInt();
doubleCd=(F-32)/9*5D;
intC=(int)Cd;
System.out.println("摄氏温度:");
System.out.println(C);
}
}

㈣ 自学Java, 求30道基础编程题目 ,我会+分

30道??我不说30道题目了..
你就做一个画图板...
再做一个聊天的..
再做一个记事本..
再做一个计算器..
再做一个小日历..

OK..你能做完这些..说明你基础60分了..不要求全部功能的实现只要实现基本功能就好了...

在下来就是编程思想..完全实现松散耦合去实现..继承..封装..多态..模型抽象...哈哈...1个就够你做的了....

答案不送上了..验证的方法就是你做的东西..你自己给自己打分吧

㈤ 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编程 类与对象的基础题

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基础编程题~

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编程中的一道基础题目,求人解答!

加一个sum = 0放在while的里面
每一次sum累加后都要归0
public class Sum1 {
public static void main(String[] args) {
int n=10;
int sum;
while(n>0){
sum=0;
for(int i=1;i<=n;i++)
sum+=i;
System.out.println("前"+n+"个数的和是"+sum);
n--;
}
}

}

㈨ JAVA编程基础问题

两题代码如下,均有标注。希望对你有帮助。

publicclassCar{
privateintspeed=0;//速度
privatebooleanon=false;//是否启动?
privatedoubleweight=1.2;//汽车重量
privateStringcolor="blue";//颜色
publicstaticvoidmain(String[]args){
//4、①用无参构造方法创建默认汽车
Carcar=newCar();
//5、创建两个car对象
Carcar1=newCar();
car1.setSpeed(120);//km/h
car1.setWeight(1.2D);
car1.setColor("black");
car1.setOn(true);
System.out.println(car1.toString());
Carcar2=newCar();
car2.setSpeed(0);//km/h
car2.setWeight(1.2D);
car2.setColor("red");
car2.setOn(false);
System.out.println(car2.toString());
}
//4、②编写设置和存取这些数据域的方法
publicintgetSpeed(){
returnspeed;
}
publicvoidsetSpeed(intspeed){
this.speed=speed;
}
publicbooleanisOn(){
returnon;
}
publicvoidsetOn(booleanon){
this.on=on;
}
publicdoublegetWeight(){
returnweight;
}
publicvoidsetWeight(doubleweight){
this.weight=weight;
}
publicStringgetColor(){
returncolor;
}
publicvoidsetColor(Stringcolor){
this.color=color;
}
//4、③toString()方法描述汽车的字符串
@Override
publicStringtoString(){
if(on){
return"当前行驶速度:"+speed+"km/h,颜色:"+color+",重量:"+weight+"吨。";
}else{
return"carisoff,颜色:"+color+",重量:"+weight+"吨。";
}
}
}

㈩ java编程基础练习题

这道题的答案是C。

double[] num1; //定义一个double类型的数组num1
double num3=2.0; //定义一个double类型的变量并赋值为2.0
int num2=5; //定义一个int类型的冰凉num2,并赋值为5
num1=new double[num2+1];
//给double类型的数组num1赋值,并初始化为5+1个大小, num2=5,所以是5+1
num1[num2]=num3;
//上面这句翻译过来就是:数组num1[5]=2.0 。 由于数组下标从0开始,所以下标为5的元素是最后一个元素。 所以答案是C

热点内容
160android 发布:2025-05-10 03:03:30 浏览:178
pythonstorage 发布:2025-05-10 02:58:38 浏览:499
如何查看电脑配置显卡参数 发布:2025-05-10 02:37:00 浏览:106
证券交易密码在哪里修改 发布:2025-05-10 02:31:56 浏览:839
javafor是什么意思 发布:2025-05-10 02:23:09 浏览:842
学生云服务器可以搭建网站吗 发布:2025-05-10 02:10:36 浏览:441
共享的文件怎么访问权限 发布:2025-05-10 02:02:49 浏览:166
如何选生信分析服务器 发布:2025-05-10 01:53:11 浏览:409
移动ip案例云dns服务器 发布:2025-05-10 01:51:46 浏览:166
侠盗飞车解压密码是多少 发布:2025-05-10 01:45:04 浏览:713