我需要用户获取给定数字的功率值(作为命令行参数)
这是我的代码,它出现了编译错误.
谁能帮帮我吗 ?
class SquareRoot{
public static void main(String args []){
double power = Math.pow(args[0]);
System.out.println("Your squared value is " + power);
}
}
Run Code Online (Sandbox Code Playgroud) 我还是java的新手,我试图创建一个内部类并在main中调用该方法.但是有一个编译错误说"非静态变量 - 这不能从静态上下文中引用"
请帮忙
class Class1{
public static void main(String args []){
Class2 myObject = new Class2();
myObject.newMethod();
}
public class Class2{
public void newMethod(){
System.out.println("Second class");
}
}
}
Run Code Online (Sandbox Code Playgroud) 这是我的任务:
编写用户输入字符串的程序,程序将其回显给监视器,每行一个字符:
C:\>java LinePerChar
Enter a string:
Octopus
O
c
t
o
p
u
s
Run Code Online (Sandbox Code Playgroud)
我试过了,但是我遇到了一些编译错误.这是我的代码:
import java.util.*;
class CharactorEcho{
public static void main(String args []){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string :");
try {
String inputString = sc.nextLine();
for(int i=0; i < sc.length(); i++) {
char c = inputString.charAt(i);
System.out.println("" + c);
}
} catch(IOException e) {
}
}
}
Run Code Online (Sandbox Code Playgroud)