私はプログラミングが初めてで、何か運動をしています。この演習では、プログラムのユーザーから3つの数字を読み取るプログラムを作成することになっています。プログラムは、最小の数を見つけ、どれが最小の数であるかを印刷することになっています。ここ は私のコードです:エラーメッセージ:operator <boolean、intには適用できません
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 to an empty string:
result = "";
if (firstnumber < secondnumber < thirdnumber)
result = firstnumber + " is the smallest number!";
if (firstnumber < thirdnumber < secondnumber)
result = firstnumber + " is the smallest number!";
if (secondnumber < firstnumber < thirdnumber)
result = secondnumber + " is the smallest number!";
if (secondnumber < thirdnumber < firstnumber)
result = secondnumber + " is the smallest number!";
if (thirdnumber < firstnumber < secondnumber)
result = thirdnumber + " is the smallest number!";
if (thirdnumber < secondnumber < firstnumber)
result = thirdnumber + " is the smallest number!";
// Making conclusion box:
JOptionPane.showMessageDialog(null, result, "Conclusion:", JOptionPane.INFORMATION_MESSAGE);
} // End of main method
} // End of class Smallestnumber
そしてここでは、エラーメッセージです:
Smallestnumber.java:29: operator < cannot be applied to boolean,int
if (firstnumber < secondnumber < thirdnumber)
^
Smallestnumber.java:32: operator < cannot be applied to boolean,int
if (firstnumber < thirdnumber < secondnumber)
^
Smallestnumber.java:35: operator < cannot be applied to boolean,int
if (secondnumber < firstnumber < thirdnumber)
^
Smallestnumber.java:38: operator < cannot be applied to boolean,int
if (secondnumber < thirdnumber < firstnumber)
^
Smallestnumber.java:41: operator < cannot be applied to boolean,int
if (thirdnumber < firstnumber < secondnumber)
^
Smallestnumber.java:44: operator < cannot be applied to boolean,int
if (thirdnumber < secondnumber < firstnumber)
^
6 errors
はどうすればプログラムが動作するように得ることができますか?
使用 '&&' '||'条件演算子 – Rahul