我使用Java使用Eclipse,我收到此错误:
"Variable name" cannot be resolved to a variable.
Run Code Online (Sandbox Code Playgroud)
有了这个Java程序:
public class SalCal {
private int hoursWorked;
public SalCal(String name, int hours, double hoursRate) {
nameEmployee = name;
hoursWorked = hours;
ratePrHour = hoursRate;
}
public void setHoursWorked() {
hoursWorked = hours; //ERROR HERE, hours cannot be resolved to a type
}
public double calculateSalary() {
if (hoursWorked <= 40) {
totalSalary = ratePrHour * (double) hoursWorked;
}
if (hoursWorked > 40) {
salaryAfter40 = hoursWorked - 40;
totalSalary = …Run Code Online (Sandbox Code Playgroud) 我正在"Java如何编程"一书中进行练习.我应该制作一个模拟掷硬币的应用程序.我应该制作一个方法(翻转),随机返回硬币的一面.我已经决定让方法返回1或2,并且在main方法中我将"转换"值表示硬币的一侧.问题是我收到一条错误消息:"类型不匹配 - 无法从int转换为boolean".我真的认为我一直只使用整数操作,并且看到了布尔语的进入情况.
代码如下:
import java.util.Random;
public class Oppgave629
{
public static void main(String[] args)
{
int command = 1;
int heads = 0;
int tails = 0;
while (command != -1)
{
System.out.print("Press 1 to toss coin, -1 to exit:");
int coinValue = flip();
if (coinValue = 1) {System.out.println("HEADS!"); heads++;}
if (coinValue = 2) {System.out.println("TAILS!"); tails++;}
System.out.printf("Heads: %d", heads); System.out.printf("Tails: %d", tails);
}
}
static int flip()
{
int coinValue;
Random randomValue = new Random();
coinValue = 1 + …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 onClickListener 中根据特定条件使 Toast 显示一些文本。该应用程序不会在模拟器中运行,并且出现以下错误:“void 无法转换为 Toast”
我四处搜索,在这个论坛上找到了几个类似的问题和解决方案,但没有一个完全适用于我的问题。其他人在声明中没有使用正确的上下文,但我的意思是我确实使用了。(javafile(上下文)的名称是:“Case1Activity”)任何人都可以帮助我吗?我稍微简化了代码:
public void onClick(View view) {
if (button1Pushed == false){
count++;
Toast toast = Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();
}
}
});
Run Code Online (Sandbox Code Playgroud) 我是编程新手,正在做som的练习.在这个练习中,我应该编写一个程序,从程序的用户读取三个数字.该程序应该找到最小的数字,并打印哪一个是最小的数字.这是我的代码:
import javax.swing.JOptionPane;
public class Smallestnumber
{
public static void main( String args[] )
{
// Defining variables:
String firstnumberstring;
String secondnumberstring;
String thirdnumberstring;
String result;
int firstnumber;
int secondnumber;
int thirdnumber;
// Making input frames:
firstnumberstring = JOptionPane.showInputDialog( "Write first number!" );
secondnumberstring = JOptionPane.showInputDialog( "Write second number!");
thirdnumberstring = JOptionPane.showInputDialog( "Write third number!" );
// Converting stringvalues to int values:
firstnumber = Integer.parseInt( firstnumberstring );
secondnumber = Integer.parseInt( secondnumberstring );
thirdnumber = Integer.parseInt( thirdnumberstring );
// Initialising printstring …Run Code Online (Sandbox Code Playgroud) 我正在学习java,使用"Java how to program"这本书.我正在解决练习.在这个实际练习中,我应该创建一个从用户读取整数的程序.然后,程序应显示与用户读取的整数相对应的方形星号(*).F.eks用户输入整数3,程序应该显示:
***
***
***
Run Code Online (Sandbox Code Playgroud)
我尝试在另一行中嵌入一个while语句,第一个在一行上重复星号,另一个在相同的时间重复这个.不幸的是,我只让程序显示一行.谁能告诉我我做错了什么?代码如下:
import java.util.Scanner;
public class Oppgave618
{
public static void main(String[] args)
{
int numberOfSquares;
Scanner input = new Scanner(System.in);
System.out.print("Type number of asterixes to make the square: ");
numberOfSquares = input.nextInt();
int count1 = 1;
int count2 = 1;
while (count2 <= numberOfSquares)
{
while (count1 <= numberOfSquares)
{
System.out.print("*");
count1++;
}
System.out.println();
count2++;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在学习Java,现在正在使用数组.我正在做一个练习,我要让用户输入一个2×3整数数组的值.然后我应该找到最小的值.我通过使用if语句来做到这一点.问题是编译器总是为最小值打印数字"0".我无法找到我的代码有什么问题.谁能帮帮我吗?代码如下:
import java.util.Scanner;
public class Oppgave79k
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int t[][] = new int[2][3];
int smallest = t[0][0];
for (int row = 0; row < t.length; row++)
{
for (int column = 0; column < t[row].length; column++)
{
System.out.println("Enter values for array: ");
t[row][column] = input.nextInt();
if (t[row][column] < smallest)
{
smallest = t[row][column];
}
}
}
for (int row = 0; row < t.length; row++)
{
for (int column = …Run Code Online (Sandbox Code Playgroud)