1. 重庆云诚科技 > 互联网资讯 >

「java基础编程教程」Java基础编程题

导读java编程十道题本文最佳回答用户:【『第⒐兲堂』】 ,现在由重庆云诚科技小编为你分析与【java基础编程教程】的相关内容!优质回答1.public class TestRandomArray{public static void main(String...

今天我们来聊聊[java基础编程教程],以下3关于Java基础编程题的观点希望能帮助到您找到想要的结果。

java编程十道题

本文最佳回答用户:【『第⒐兲堂』】 ,现在由重庆云诚科技小编为你分析与【java基础编程教程】的相关内容!

优质回答1.

public class TestRandomArray

{

public static void main(String[] args)

{

int maxline = (int) (Math.random()*100);

int[] array = new int[maxline];

for(int i=0;i<maxline;i++)

{

int temp = (int) (Math.random()*100);

if(temp>=10&&temp<=99)

{

array[i] = temp;

}

else

i--;

}

for(int j=0;j<maxline;j++)

{

int max = array[0];

if(array[j]>max)

{

max=array[j];

array[j] = array[0];

array[0] = max;

}

}

for(int k=0;k<maxline;k++)

{

System.out.print(array[k]+" ");

}

}

}

2.

public class TestNumber100

{

public static void main(String[] args)

{

for(int i=1;i<100;i++)

{

if(i%3==0&&(i%5!=0)&&(i%9!=0))

System.out.println(i+" ");

else

continue;

}

}

}

3.貌似没结果

public class Test3

{

public static void main(String[] args)

{

/*for(int i=0;i<=9;i++)

{

for(int j=0;j<=9;j++)

{

int code = 10000+i*1000+j*100+23;

if((code%57)==0&&(code%67)==0&&i!=j)

{

System.out.println("x="+i+","+"y="+j);

}

else

System.out.println(i+" "+j);

}

}*/

for(int i=10023;i<=19923;i++)

if(i==0&&i==0)

System.out.println(i+" ");

}

}

4.

class Caculate {

int money;

Caculate(){

money = 10;

}

public int charge (int distance){

if (distance < 3){

money = 10;

}

if ((distance >= 3) && distance < 15)

{

money = money + 2*(distance-3);

}

if (distance > 15 )

{

money = money + 2*12 + 3*(distance - 15);

}

return money;

}

public static void main(String args[]) {

System.out.println("请输入公里数");

int distance_example=0;

Scanner key = new Scanner(System.in);

int n = key.nextInt();

distance_example = n;

Caculate pay = new Caculate();

pay.money = pay.charge(distance_example);

System.out.println("You need to pay money:"+pay.money+" distance is:"+distance_example);

}

}

5.

public class Test4

{

public static void main (String args[])

{

int n=100;

while(n<=1000)

{

int i,j,k;

i=n/100;

j=(n-i*100)/10;

k=n%10;

if((Math.pow(i, 3)+Math.pow(j, 3)+Math.pow(k, 3))==n)

System.out.print(n+String.valueOf('\t'));

n++;

}

}

}

6.

public class TestMoney

{

public static void main(String[] args)

{

int one=1,two=2,five=5;

for(int i=1;i<100;i++)

for(int j=1;j<50;j++)

for(int k=1;k<20;k++)

{

if((i*one+j*two+k*five)==100)

System.out.println(i+"个一分,"+j+"个两分,"+k+"个五分");

}

}

}

7.

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class TestJieCheng

{

public static void main (String args[])

{

int a=0,b=1;float sum=0;

System.out.print("请输入要计算的阶乘:");

try

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

a=Integer.parseInt(in.readLine());

}catch(IOException e){}

for(int i=1;i<=a;i++)

{

b=b*i;

}

System.out.print(a+"的阶乘是"+b);

}

}

8.

public class Test4

{

public static void main (String args[])

{

int n=100;

while(n<=1000)

{

int i,j,k;

i=n/100;

j=(n-i*100)/10;

k=n%10;

if((Math.pow(i, 3)+Math.pow(j, 3)+Math.pow(k, 3))==n)

System.out.print(n+String.valueOf('\t'));

n++;

}

}

}

9.

public class TestNumber2

{

public static void main(String[] args)

{

final int maxline = 20;

double sum = 0;

double [] denominator = new double [maxline];

double [] numerator = new double [maxline];

for(int i=2;i<denominator.length;i++)

{

denominator[0]=1;

denominator[1]=2;

denominator[i]=denominator[i-1]+denominator[i-2];

}

for(int j=2;j<numerator.length;j++)

{

numerator[0]=2;

numerator[1]=3;

numerator[j]=numerator[j-1]+numerator[j-2];

}

for(int k=0;k<maxline;k++)

{

sum+=(numerator[k])/denominator[k];

}

System.out.println(sum);

}

}

10.

import java.io.*;

public class 根据输入的三个数求一元二次方程

{

public static void main (String args[]) throws NumberFormatException, IOException

{

float a[]=new float [3];

for(int i=0;i<a.length;i++)

{

System.out.println("请输入第"+(i+1)+"个数");

BufferedReader in =new BufferedReader(new InputStreamReader(System.in));

a[i]=Float.parseFloat(in.readLine());

}

float x1=0,x2=0;

x1=(float) ((((-1)*a[1])+(Math.sqrt(a[1]*a[1]-4*a[0]*a[2])))/(2*a[0]));

x2=(float) ((((-1)*a[1])-(Math.sqrt(a[1]*a[1]-4*a[0]*a[2])))/(2*a[0]));

System.out.print(a[0]+"X2"+a[1]+"X"+a[2]+"的两个根是:");

System.out.print(x1+"和"+x2);

}

}

上文就是重庆云诚科技小编分享贡献者:(『第⒐兲堂』)分析的关于“java编程十道题”的问题了,不知是否已经解决你的问题?如果没有,下一篇内容可能是你想要的答案,下面继续讲析下文用户【恋你的.心℡不变♂】贡献的“java编程题 本人新手,求详解。”的一些相关疑问做出分析与解答,如果能找到你的答案,可以关注本站。

java编程十道题

java编程题 本人新手,求详解。

本文最佳回答用户:【恋你的.心℡不变♂】 ,现在由重庆云诚科技小编为你解答与【java基础编程教程】的相关内容!

优质回答先看下最终的结果吧,是不是你想要的?

项目结构如下图所示:

其中,Student是父类,PostGraduate是子类,继承自父类Student,Main是主类,用于创建对象以及把这些对象的功能调用起来。

---------------------------Student代码如下:------------------------------

/**

 * 学生类

 * @author 逍遥

 *

 */

public class Student {

//学号

private int sId;

//姓名

private String sName;

//数学成绩

private double mathScore;

//计算机成绩

private double computerScore;

/**

* 获取学号

* @return

*/

public int getsId() {

return sId;

}

/**

* 设置学号

* @param sId

*/

public void setsId(int sId) {

this.sId = sId;

}

/**

* 获取姓名

* @return

*/

public String getsName() {

return sName;

}

/**

* 设置姓名

* @param sName

*/

public void setsName(String sName) {

this.sName = sName;

}

/**

* 获取数学成绩

* @return

*/

public double getMathScore() {

return mathScore;

}

/**

* 设置数学成绩

* @param mathScore

*/

public void setMathScore(double mathScore) {

this.mathScore = mathScore;

}

/**

* 获取计算机成绩

* @return

*/

public double getComputerScore() {

return computerScore;

}

/**

* 设置计算机成绩

* @param computerScore

*/

public void setComputerScore(double computerScore) {

this.computerScore = computerScore;

}

/**

* 输出成员变量(4个成员变量)的信息。

*/

public void print(){

System.out.println("学号:"+sId);

System.out.println("姓名:"+sName);

System.out.println("计算机成绩:"+mathScore);

System.out.println("数学成绩:"+computerScore);

}

}

---------------------------Student代码结束------------------------------

---------------------------PostGraduate代码如下:------------------------------

/**

 * 研究生类

 * @author 逍遥

 *

 */

public class PostGraduate extends Student{

//导师姓名

private String tName;

//研究方向

private String ResearchDirection;

/**

* 获取导师姓名

* @return

*/

public String gettName() {

return tName;

}

/**

* 设置导师姓名

* @param tName

*/

public void settName(String tName) {

this.tName = tName;

}

/**

* 获取研究方向

* @return

*/

public String getResearchDirection() {

return ResearchDirection;

}

/**

* 设置研究方向

* @param researchDirection

*/

public void setResearchDirection(String researchDirection) {

ResearchDirection = researchDirection;

}

/**

* 研究生类重写父类的void print()方法,功能是输出成员变量(6个成员变量)的信息

*/

@Override

public void print() {

// TODO Auto-generated method stub

super.print();

System.out.println("导师姓名:"+tName);

System.out.println("研究方向:"+ResearchDirection);

}

}

---------------------------PostGraduate代码结束------------------------------

---------------------------Main代码如下:------------------------------

import java.util.Scanner;

/**

 * 主类

 * @author 逍遥

 *

 */

public class Main {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

//用于获取从键盘上输入的信息

Scanner input=new Scanner(System.in);

//创建一个Student类的对象

Student student=new Student();

//从键盘上输入其属性信息

System.out.print("请输入学生的学号:");

student.setsId(input.nextInt());

System.out.print("请输入学生的姓名:");

student.setsName(input.next());

System.out.print("请输入学生的数学成绩:");

student.setMathScore(input.nextDouble());

System.out.print("请输入学生的计算机成绩:");

student.setComputerScore(input.nextDouble());

//并且通过其print方法输出这些信息;

student.print();

//创建一个PostGraduate类的对象

PostGraduate postGraduate=new PostGraduate();

//从键盘上输入其属性信息

System.out.print("请输入研究生的学号:");

postGraduate.setsId(input.nextInt());

System.out.print("请输入研究生的姓名:");

postGraduate.setsName(input.next());

System.out.print("请输入研究生的数学成绩:");

postGraduate.setMathScore(input.nextDouble());

System.out.print("请输入研究生的计算机成绩:");

postGraduate.setComputerScore(input.nextDouble());

System.out.print("请输入研究生的导师姓名:");

postGraduate.settName(input.next());

System.out.print("请输入研究生的研究方向:");

postGraduate.setResearchDirection(input.next());

//并且通过其print方法输出这些信息。

postGraduate.print();

}

}

---------------------------Main代码结束------------------------------

=================知识点的简单总结=================

本题考察的知识点是面向对象的三大特性之一:继承。

Student为父类,包含了学号、姓名、数学成绩和计算机成绩4个属性,以及一个print()方法。

PostGraduate 继承父类的时候,继承了父类中的所有方法,因为方法我都是用的public,而属性继承不了,因为我在父类中用了封装,所有属性都用private修饰了,想访问属性的话,必须通过get、set方法,这里,我重写了父类中的print方法,通过super.print();调用了父类中的print()方法。

最后就是Main类,提供了main方法作为入口函数,用于按要求声明这些对象以及去调用对象中的方法。

以上就是重庆云诚科技小编解答(恋你的.心℡不变♂)分析关于“java编程题 本人新手,求详解。”的答案,接下来继续为你详解体育用户(十年萤火照君眠)贡献“JAVA基础编程题~”的一些相关解答,希望能解决你的问题!

JAVA基础编程题~

本文最佳回答用户:【十年萤火照君眠】 ,现在由重庆云诚科技小编为你探讨与【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基础编程教程]的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java基础编程教程、Java基础编程题的信息别忘了在本站进行查找喔。

推荐文章:

  • 膜的组词和部首,膜的组词和拼音是什么
  • 亲字组词100个 亲字的组词有
  • 酬谢是什么意思,定当酬谢是什么意思
  • 异的组词和部首,株的组词和部首
  • 箭组词和拼音 耸组词和拼音部首
  • 有志不在年高的意思-有志不在年高的意思雨来表达了
  • 繁衍的意思 繁衍的意思简单解释
  • 彤组词,胀组词和拼音
  • 血泊的拼音 泊的拼音
  • 螺组词拼音 螺的组词和拼音
  • 本文由网上采集发布,不代表我们立场,转载联系作者并注明出处:https://www.cqycseo.com/zixun/4582.html

    联系我们