你能检查java答案吗 [英] can you check java answer

查看:76
本文介绍了你能检查java答案吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的作业:
编写一个程序,它将执行以下任务.声明并初始化两个变量,这些变量代表两个测试中学生的分数.平均成绩应通过将测试分数相加并除以2来计算.然后,应根据平均成绩确定字母等级.应使用以下评分:A = 90-100,B = 80-89,C = 70-79,D = 65-69,F = 64以下.该程序应显示平均考试成绩和学生的字母成绩.

我的回答(您可以检查并修复):

my Assignment:
Write a program that will do the following tasks. Declare and initialize two variables that represent a student''s scores on two tests. The grade average should be computed by summing the test scores and dividing by 2. Then, a letter grade should be determined based on the average grade. The following scoring shall be used: A = 90-100, B = 80-89, C = 70-79, D = 65-69, F = 64 or less. The program should display the average test score and the student''s letter grade.

My answer (can you check and fix):

public class TestGrades
{
    public static void main (String [] args)
    {
        int gradeone=75;
        int gradetwo=80;
        int testscore= ((gradeone + gradetwo)/2);
        char grade;

        System.out.println("\n" + "your test score is" + testscore);

        if(testscore >= 90 )
  	  grade='A';
		
	elseif(testscore >= 80 );
	  grade='B';

	elseif(testscore >= 70 );
	  grade='C';
		
	elseif(testscore >= 65 );
	  grade='D';

	else
	  grade='F';
    }
}

推荐答案

我们不做作业:它的设置是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.
自己尝试一下,您可能会发现它并不像您想的那样困难!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!


您有很多问题,但是如果尝试运行,编译器应指出这些问题. br/>
但是,这里是我看到的问题的简要概述:
-else if应该是两个单词,它们之间没有空格
-else if行的末尾不应使用分号
-正如Wes提到的,您忘了显示成绩

还有一些提示:
-您不需要连接字符串文字,可以将"\n" + "your test score is"更改为"\nyour test score is"
-您可能也想在该字符串的末尾添加一个空格,否则您将得到类似您的测试成绩为76"的输出,而不是您的测试成绩为76"的输出.
-即使主体中只有一行的if语句不需要{和},也要使用它们.如果您以后要添加另一行,则很难添加它们,并且大多数Java IDE都会在您键入开头的括号时添加结尾括号.
You have a couple problems, but if you try to run it these should be pointed out by the compiler.

But, here''s a quick rundown of the problems I see:
- else if should be two words, you have no space between them
- There should not be a semicolon at the end of your else if lines
- As mentioned by Wes, you forgot to display the grade

And some tips:
- You shouldn''t need to concatenate string literals, you can change "\n" + "your test score is" to just "\nyour test score is"
- You probably want to add a space to the end of that string as well, or you''ll get output like "your test score is76" instead of "your test score is 76"
- Even though { and } aren''t required for if statements with only one line in the body, use them anyways. If you ever want to add another line later it''s a pain to add them then, and most Java IDEs will add the closing brace when you type the opening one.


我看到有一些条件错误(考虑一个案例,如果您的测试分数为95,那么该分数将是多少?因为所有条件都满足),否则条件会更好.
I see there are some conditional errors(consider a case,if your testscore is 95 then what will be the grade?because all conditions true for it) in your if else conditions..it will work better just like as it..
    if(testscore >= 90 )
  grade='A';

else if((testscore >= 80 ) && (testscore < 90))
  grade='B';

else if((testscore >= 70 ) && (testscore < 80))
  grade='C';

else if((testscore >= 65 ) && (testscore < 70))
  grade='D';

else
  grade='F';


lewax00还会通知您一些语法错误.


there are also some syntax errors which is informed you earlier by lewax00..


这篇关于你能检查java答案吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆