纯java新生学习第二天遇到问题求解答,是讲师留的assignment,感恩的心
问题1:
public class DebugTwo1
{
public static void main(String[] args)
{
int a = 315;
double b = 12.4;
System.out.print("The int is ");
System.out.println(int);
System.out.print("The double is ");
System.out.println(double);
}
}
int 和 double输出有问题
问题2:
```java
public class DebugTwo2
// This application performs arithmetic with two integers
{
public static void main(String args[])
{
int a, b;
7 = a;
4 = b;
System.out.println("The sum is '+ a + b'");
System.out.println("The difference is '+ a - b'");
System.out.println("The product is '+ a * b'");
}
}
错误提示7和4是变量
问题3:
public class DebugTwo3
// Demonstrates remainder and output
{
public static void main(String args[])
{
double a = 99, b = 8 ;
int c = 77;
result = a % b;
System.out.println("Divide " + a + " by " + b);
System.out.println("remainder is " + result);
System.out.print("c is a very large number:");
System.out.println(c);
}
}
result不能被解析为一个变量
在网上查了还是没看懂,求解,谢谢!~
第一个代码: 要打印 变量名 a和b,而不是打印变量类型。 第二个代码: 给变量赋值时,变量名应该在前边。 如a=7 第三个代码: 使用变量时,要先申明变量,如 double result = a % b;正确回答如下:
问题1
public class DebugTwo1
{
public static void main(String[] args)
{
int a = 315;
double b = 12.4;
System.out.print("The int is ");
System.out.println(a);
System.out.print("The double is ");
System.out.println(b);
}
}
问题2
public class DebugTwo2
// This application performs arithmetic with two integers
{
public static void main(String args[])
{
int a, b;
a=7;
b=4;
System.out.println("The sum is"+ a + b);
System.out.println("The difference is"+ a - b);
System.out.println("The product is "+ a * b);
}
}
问题三 double result
public class DebugTwo3
// Demonstrates remainder and output
{
public static void main(String args[])
{
double a = 99, b = 8 ;
int c = 77;
int result = a % b;
System.out.println("Divide " + a + " by " + b);
System.out.println("remainder is " + result);
System.out.print("c is a very large number:");
System.out.println(c);
}
}