Java课程主观题作业_JAVA课程作业01

1.设计思想:    首先要从键盘接受多个数字,然后求和。我们可以利用数组,设置一个常量final int n;

int a【】=new int【n】;然后利用Integer.parseInt()从键盘接收数据,然后求和输出。

2.程序流程图:

1 引入包(用于输入的Scanner和设计输入框的JOptionPane)

2 定义一个常量n,final int n;用于数组的设定。

3 定义数组 int a【】=new int 【n】;

4 利用Scanner的对象或Integer.parseInt()从键盘读取数据

5 求和输出

6 主程序设计完后再设计框及其他提示符等

3 源代码:

import javax.swing.JOptionPane;

import java.util.Scanner;

public class JavaArgument {

public static void main(String[] args) {

Scanner lnput=new Scanner(System.in);

String q;

final int n;

int sum=0;

q=JOptionPane.showInputDialog("Please input n :" );

n=Integer.parseInt(q);

String b[]=new String[n];

int a[]=new int[n];

for(int i=0;i

{ int j=i+1;

b[i]=JOptionPane.showInputDialog( "Please input "+j+" number" );

a[i]= Integer.parseInt( b[i] );

sum=sum+a[i];

}

JOptionPane.showMessageDialog(

null, "The sum is " + sum, "Results",

JOptionPane.PLAIN_MESSAGE );

}

}

4 实验截图:

6b2aab84ab9de2c2179296a96d3b224e.png

d8f76fa302f374c511069a500645fcdf.png

1364900e07ddaf4783c46599a43cdd3c.png

5d7d9025c14a2faa3bbd35d69fffb39b.png

c1f653515103918ac7b5673dbc3cb1b6.png

c14902218b989b7ef2111c3ba7d9cde3.png

ed50bbafa2db9adb20754be3526e2b3c.png

18e393cb7f91aa086d4a5d958fef5248.png

07d26a5040a41c04732815fab3e1682d.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个Java主观题判断代码的示例: ``` public class SubjectiveQuestion { private String question; private String expectedAnswer; public SubjectiveQuestion(String question, String expectedAnswer) { this.question = question; this.expectedAnswer = expectedAnswer; } public boolean isCorrect(String answer) { return answer.equals(expectedAnswer); } public String getQuestion() { return question; } public String getExpectedAnswer() { return expectedAnswer; } } ``` 这个类表示一个主观题,它包含一个问题和预期答案。它有一个名为isCorrect的方法,该方法接受一个实际答案并返回一个布尔值,表示该答案是否与预期答案匹配。它还有两个getter方法,分别用于获取问题和预期答案。 使用该类的示例代码: ``` SubjectiveQuestion question = new SubjectiveQuestion("What is the capital of France?", "Paris"); // Answer the question with incorrect answer String answer1 = "London"; System.out.println(question.isCorrect(answer1)); // false // Answer the question with correct answer String answer2 = "Paris"; System.out.println(question.isCorrect(answer2)); // true ``` 此示例创建一个主观问题,即“法国的首都是什么?”,预期答案为“巴黎”。然后,它尝试使用“伦敦”和“巴黎”答案来回答问题。第一个答案不正确,第二个答案是正确的。由于我们在Question类中使用的判断方法,它将返回正确的布尔值,以反映答案是否正确。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值