我已经开始学习java并且正在为这种练习编写代码.请告诉我哪里出错了,它说我在第27行有一个非法的表达.
import java.util.Scanner; public class steps { public static void main(String []args) { Scanner Keyboard = new Scanner(System.in); print("What is your name?"); String name = Keyboard.nextLine(); print("What is five + five?"); String number = Keyboard.nextLine(); String gj = (", Good Job"); switch (number){ case "ten": print("correct" + gj + (" ") + name); break; case "Ten": print("correct" + gj +(" ") + name); break; case "10": print("correct" + gj +(" ") + name); break; default: print("Wroung try again"); } static void print(String s) { // <--- this is line 27 System.out.println(s); } } // <--- there is no trailing } here?
Pradeep Simh.. 5
您无法在Java中的方法中定义方法,将此代码移出您的main()
方法:
static void print(String s){ System.out.println(s); }
仔细看看你的大括号,这是明确的代码缩进将有助于.
您无法在Java中的方法中定义方法,将此代码移出您的main()
方法:
static void print(String s){ System.out.println(s); }
仔细看看你的大括号,这是明确的代码缩进将有助于.