配置都正确,在控制台动手编译其他的源码可以通过,控制台编译输出菱形的源码就不行,用IDE就是可以,为什么啊?[code=java/*]
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/ /**
*
* @author Xiao
*/
package com.mingrisoft;
public class Demo {
public static void main(String[] args) {
printHollowRhombus(10);
}
public static void printHollowRhombus(int size) {
if (size % 2 == 0) {
size++; // 计算菱形大小
}
for (int i = 0; i < size / 2 + 1; i++) {
for (int j = size / 2 + 1; j > i + 1; j--) {
System.out.print(" "); // 输出左上角位置的空白
}
for (int j = 0; j < 2 * i + 1; j++) {
if (j == 0 || j == 2 * i) {
System.out.print("*"); // 输出菱形上半部边缘
} else {
System.out.print(" "); // 输出菱形上半部空心
}
}
System.out.println("");
}
for (int i = size / 2 + 1; i < size; i++) {
for (int j = 0; j < i - size / 2; j++) {
System.out.print(" "); // 输出菱形左下角空白
}
for (int j = 0; j < 2 * size - 1 - 2 * i; j++) {
if (j == 0 || j == 2 * (size - i - 1)) {
System.out.print("*"); // 输出菱形下半部边缘
} else {
System.out.print(" "); // 输出菱形下半部空心
}
}
System.out.println("");
}
}
}
[/code]
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/ /**
*
* @author Xiao
*/
package com.mingrisoft;
public class Demo {
public static void main(String[] args) {
printHollowRhombus(10);
}
public static void printHollowRhombus(int size) {
if (size % 2 == 0) {
size++; // 计算菱形大小
}
for (int i = 0; i < size / 2 + 1; i++) {
for (int j = size / 2 + 1; j > i + 1; j--) {
System.out.print(" "); // 输出左上角位置的空白
}
for (int j = 0; j < 2 * i + 1; j++) {
if (j == 0 || j == 2 * i) {
System.out.print("*"); // 输出菱形上半部边缘
} else {
System.out.print(" "); // 输出菱形上半部空心
}
}
System.out.println("");
}
for (int i = size / 2 + 1; i < size; i++) {
for (int j = 0; j < i - size / 2; j++) {
System.out.print(" "); // 输出菱形左下角空白
}
for (int j = 0; j < 2 * size - 1 - 2 * i; j++) {
if (j == 0 || j == 2 * (size - i - 1)) {
System.out.print("*"); // 输出菱形下半部边缘
} else {
System.out.print(" "); // 输出菱形下半部空心
}
}
System.out.println("");
}
}
}
[/code]
解决方案 »
- Java中的动态绑定机制,很迷糊。。
- JTree父节点和叶子节点用图片显示
- 强制类型转换异常。自动封装出现问题?
- 奇怪问题??? 关于.jar 文件的执行????
- ----如何将一个文本中的table键用空格替换-------
- linux 下java打印pdf文件
- 大家帮我看看JAVAC编译哪里出了错!!!
- 请问如何将string字符串转换为double型?
- 紧急求救,用java.Swing组件监听两个table (ListSelectionListener)
- 为什么我点了一个程序的run as后面的Java application程序没有运行出或任何结果,而且这个程序仅仅是最简单的hello world,
- java开发关于POI工具类的问题,求大神指点
- 最新版的mac装完jdk1.8后用终端查询依旧是jdk1.6,暂时无解
把Demo.java放在跟包名一致的路径下,假设你的开发目录是:e:\javadev,那么应该放在
e:\javadev\com\mingrisoft\Demo.java
编译时可以在Demo.java当前目录下,但执行时不可以
执行时类名要带包名,要么在e:\javadev,执行java com.mingrisoft.Demo
要么在classpath环境变量加上e:\javadev,这时在其它目录执行java com.mingrisoft.Demo就可以了