配置都正确,在控制台动手编译其他的源码可以通过,控制台编译输出菱形的源码就不行,用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]

解决方案 »

  1.   

    调用时候加上-cp指定路径,或者直接cd到当前class在的路径-cp ./ 这样
      

  2.   

    命令行运行的话把第一行的package去掉就行了
      

  3.   

    包路径的问题
    把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就可以了