编程语言
首页 > 编程语言> > 自测题: Java 基础

自测题: Java 基础

作者:互联网

1.19 自测题:

  1. 什么是字节码?它对Java的Internet程序设计为何十分重要?

字节码是一种高度优化的指令集,由Java虚拟机执行,可帮助Java获得可移植性和安全性

  1. 面向对象程序设计的三个主要原则是什么?

封装、多态性和继承

  1. Java程序从何处开始执行

Java程序从main()方法开始执行

  1. 什么是变量

变量是一种命名的内存地址,可以在程序运行的时候修改遍变量的内容

  1. 下列哪几个变量是无效的?

    • count
    • $count
    • count27
    • 67count (变量名不能以数字开头)
  2. 如何创建单行注释和多行注释?

单行注释以‘ // ’开始,在行尾结束;多行注释以‘ / * ’开始,以‘ */ ’结束

  1. 写出if语句和for循环的形式

if(condition) statement;

for(initialization;condition;iteration) statement;

  1. 如何创建代码块?

代码块以‘ { ’开始,以’ } '结束

A block of code is started with a { and ended with a }.

  1. 月球重力为地球重力的17%,编写一个程序来计算你在月球上的实际体重
package io.github.Joeo8;
import java.util.Scanner;
//月球上的重力是地球的17%,请编写一个程序来计算你在月球的实际体重
public class Weigth {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入你当前的体重值: ");
        double weight = sc.nextDouble();
        WeightMath(weight);
    }
    public static  void WeightMath(double weight){
        double RealWeight = weight * 0.17;
        System.out.println("你在月球的真实体重为: "+RealWeight);
    }
}
/*
    Compute your weight on the moon.
    Call this file Moon.java
*/
package io.github.Joeo8;
class Moon {
    public static void main(String[] args) {
        double earthweight; // weight on earth
        double moonweight; // weight on moon
        earthweight = 165 ;
        moonweight = earthweight * 0.17;
        System.out.println(earthweight +
                " earthweight is equivalent to " +
                moonweight + " moon-pounds.");
    }
}
  1. 改编练习1-2,打印从英寸到米的转换。转换12英寸,一英寸一英寸地转换:每12英寸输出一个空行(1米约等于39.27英寸)
package io.github.Joeo8;
//写一个单位转换程序,从英寸到米 (1米约等于39.37英寸)
//要求转换12英尺(一英尺==12英寸),每12英寸输出一个空行
public class InchToMeter {
 public static void main(String[] args) {
     Exchange();
 }
 public static  void Exchange(){
     for (double in = 1; in <= 12*12 ;in++) {
         double me = in / 39.37;
          System.out.println(in+"  inch is vaule of  "+me+"  meter");
          if (in % 12 == 0){
              System.out.println();
          }
     }
 }
}
//在这个程序中遇到的问题

标签:12,Java,weight,double,基础,System,自测题,public
来源: https://blog.csdn.net/qq_43353521/article/details/110039510