私はかなり新しいJavaを使い、学校のために何かを作りました。 私の問題は最後のIf文です。私は文字列を比較して、それを理解します!=または> = doesntの仕事ですが、私はその代わりに何を使うべきか理解していません。どんな助け?は私のJavaプログラムの問題に遭遇しました
私は、その行を使用する適切な方法を探してみましたが、私はちょうど本当に2文字を比較するときに誰もが何を述べていたか理解していません。
package Secrets_hw2p1;
/**
*
* @author secrets
*/
//importing Scanner
//import scanner
import java.util.Scanner;
public class secrets_hw2p1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//Creating the Scanner object
Scanner input = new Scanner (System.in);
//getting students goal grade
System.out.println("What is your Goal Letter Grade? ");
String goalGrade = input.next();
//Enter assignment scores. and read scores
System.out.println("Please enter in your two assignment scores followed"
+"by your two exam scores one at a time followed by enter ");
float assignment1 = input.nextFloat();
float assignment2 = input.nextFloat();
float exam1 = input.nextFloat();
float exam2 = input.nextFloat();
//calculations of averages
double goal = assignment1 * .40 + assignment2 * .40 + exam1 * .30 +
exam2 * 0.30;
int grade;
//Calculate Letter grade
if (goal >= 90)
grade = 'A';
else if (goal >= 80)
grade = 'B';
else if (goal >= 70)
grade = 'C';
else
grade = 'D';
//prompt the user for how they want there grade
System.out.println("Press 1 to display letter grade or press 2 to"
+"see if you met your goal ");
double number = input.nextDouble();
//if user inputed 1
if (number == 1)
System.out.println ("Final grade:" + grade);
//if user inputed 2
if (number == 2)
if (goalGrade != grade)
System.out.println("You have not met or exceeded your goal"
+" grade");
else if (c1.goalGrade >= grade)
System.out.println("You met or exceded your goal grade !");
}
}
'grade'は' STRING'する必要がありたいと思います。そして、あなたは 'equals()'を使って文字列を比較するべきです。 – shmosel
「私のJavaプログラムで問題が発生しました」というのはStackOverflowの質問にとっては貧弱なタイトルです。もっと有益な質問タイトル、実際の問題を要約した質問タイトルを使用することを検討してください。これにより、より良いヘルプを得るのに役立ちます。詳細については、[ツアー]、[ヘルプ]、[良い質問をする方法](http://stackoverflow.com/help/how-to-ask)のセクションを参照してください。あなたの現在および将来の質問を改善するのに役立ち、より良い回答を得るのに役立ちます。 –
@shmoselまたは 'char'は可能ですが、文字リテラルを格納するために' int'が使用されているのは間違いです。 –