
正文
java编程案例代码,JAVA编程案例
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
简单的JAVA编程例子
编写显示学生的学号、姓名的程序。包括用来设置和获得学生的学号、姓名数据的单独方法。创建2个员工对象
这样的问题,你试一下可以用jb来做啊。方法应该很简单的。以前有做过~~~都是用jb做的~~~~~~~~~
相关问答
Q1: Java编程(写出程序代码)
import java.util.Scanner;
/*输入一个成绩,将该成绩转换为A、B、C、D和E:成绩在90分以上,结果为A,成绩在80-90之间,结果为B,成绩在70-80之间,结果为C,成绩在60-70之间,结果为D,成绩在60分以下,结果为E。*/
public class Chengfabiao
{
public static void main (String[] args)
{
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
if(score90)
{
System.out.println("A");
}
else if(score=80)
{
System.out.println("B");
}
else if(score=70)
{
System.out.println("C");
}
else if(score=60)
{
System.out.println("D");
}
else
{
System.out.println("E");
}
}
}
Q2: 一个简单的Java程序代码?
package com.zpp;public class Charge {
public static void main(String [] args) {
if(args.length ==0) {
System.out.println("parameter error!");
System.out.println("java com.zpp.Charge [int]");
return;
}
int min = Integer.parseInt(args[0]);
double money = 0.0;
if (min = 0) {
money =0.0;
System.out.println("not money");
} else if (min = 60) {
money = 2.0;
} else {
money = 2.0 + (min - 60) * 0.01;
}
System.out.println("please pay: " + money);
}
} 编译:javac -d . Charge.java运行:java com.zpp.Charge 111
Q3: 编程java 求代码
有 4 个 java 文件,分别是 Shape.java,Square.java,Circle.java,ShapeTest.java。其内容如下:
Shape.java
package graphics;
interface class Shape {
double getArea();
double getPerimeter();
}
Square.java:
package graphics;
public class Square implements Shape {
private double x;
private double y;
private double width;
private double height;
public Square(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public Square(double x0, double y0, double x1, double y1) {
double xmin = x0 x1 ? x1 : x0;
double ymin = y0 y1 ? y1 : y0;
this.x = xmin;
this.y = ymin;
this.width = x0 + x1 - 2*xmin;
this.height = y0 + y1 - 2*ymin;
}
@Override
public double getArea() {
return this.width * this.height;
}
@Override
public double getPerimeter() {
return 2 * (this.width + this.height);
}
}
Q4: java编程(写出程序代码)
public class Test {
public static void main(String[] args) {
// 定义数组
int[][] array = new int[5][6];
// 生成随机数初始化数组
for (int i = 0; i array.length; i++) {
for (int j = 0; j array[i].length; j++) {
array[i][j] = (int) (40 * Math.random()) + 10;
}
}
// 输出数组
for (int i = 0; i array.length; i++) {
for (int j = 0; j array[i].length; j++) {
System.out.print(array[i][j] + "\t");
}
System.out.println(); // 换行
}
}
}
Q5: 用JAVA的do-while语句编写程序例子
public class SimpleDoWhile {
public static void main(String[] args) {
int index = 1;
do {
System.out.println(index);
index = index + 1;
} while(index = 10);
System.out.println("DONE.");
}
}
输出结果为:
do...while 循环是 while 循环的变体。在检查while()条件是否为真之前,该循环首先会执行一次do{}之内的语句,然后在while()内检查条件是否为真,如果条件为真的话,就会重复do...while这个循环,直至while()为假。
do-while 循环语法格式:
do
{
循环体;
}
while (条件表达); //条件表达,可以引用外传感器返回值。
扩展资料:
do...while 和 while循环非常相似,区别在于表达式的值是在每次循环结束时检查而不是开始时。
和正规的 while 循环主要的区别是 do-while 的循环语句保证会执行一次(表达式的真值在每次循环结束后检查),然而在正规的 while 循环中就不一定了(表达式真值在循环开始时检查,如果一开始就为 FALSE 则整个循环立即终止)。
总结:while循环是先判断后循环 ,而do–while循环是先循环后判断。
参考资料:do while-百度百科







