注册 登录
编程论坛 JAVA论坛

求解。分开方法。总是报错啊、

guoluqiang 发布于 2016-12-12 11:43, 1630 次点击
package com.guoluqiang;

import java.util.Scanner;

public class Test {
    public void tese(){
        Scanner sc = new Scanner(System.in);
        
        Commodity s = new Commodity();
        System.out.println("商品名称");
        s.name = sc.next();
        System.out.println("商品数量");
        s.quantity = sc.next();
        System.out.println("商品单价");
        s.unit_price = sc.next();
        System.out.println("商品单位");
        s.unit = sc.next();
        System.out.println("商品分类");
        s.classify = sc.next();
        System.out.print(s.name+" "+s.quantity+" "+s.unit_price+" "+s.unit+" "+s.classify+" ");
    public void{这里总是报错啊。。。大神求解。
            Commodity[] d = new Commodity[3];
            for(int i = 0; i < 3; i++){
            Commodity t = new Commodity();
            System.out.println("商品颜色");
            t.color = sc.next();
            d[i] = t;
            }
            for(int j = 0; j < 3;j++){
                System.out.print(d[j].color+" ");
            }
        }
        }
   
   
    public static void main(String[] args) {
        
        Test s = new Test();
        s.tese();   
    }   
}
怎么分开啊。
5 回复
#2
孤独与烈酒2016-12-13 08:39
你那块都没有方法名  当然会报错
#3
GrayJerry2016-12-13 13:58
你把方法定义到另一个方法的方法体里面了
#4
kaosaier2016-12-13 21:06
回复 楼主 guoluqiang
你那块都没有方法名  当然会报错
#5
x178038687852016-12-15 23:31
为什么没定义方法名
#6
GrayJerry2016-12-16 17:05
public void{这里没有方法名,而且你的这种写法,方法不能定义在方法里面
1