关于一个参数应用的问题

buchjava 2008-01-10 09:25:37
小弟刚学JAVA 对JAVA思想很模糊 请多指教!
我想将方法public static vodi moth(int x, int y, int z) 里面的参数应用到语句Student st =new Student();里面,达到完成选择语句并输出内容。(最好用io写)谢谢了!
class Student
{
public static void moth(int x, int y, int z)
{

switch(x)
{
case 1:
System.out.print("小于60分以下的成绩:");
System.out.println("59");
break;
case 2:
System.out.println("65");
break;
case 3:
System.out.println("88");
break;

}

switch(y)
{
case 1:
System.out.println("59");
break;
case 2:
System.out.print("大于60分以上的成绩:");
System.out.println("65 88");
break;
case 3:
System.out.println("88");
break;
}

switch(z)
{
case 1:
System.out.println("59");
break;
case 2:
System.out.println("65");
break;
case 3:
System.out.print("最高成绩:");
System.out.println("88");
}

}
public static void main(String[] args)
{
Student st =new Student();
String mark = st.moth(x=59);
String mark = st.moth(y=65);
String mark = st.moth(z=88);

}
}
...全文
85 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cursor_wang 2008-01-10
  • 打赏
  • 举报
回复
改了下.你可以选择输入几个学生成绩.
import java.util.*;
class Student{
int score;
public Student(int k){
this.score=k;
}

public static void moth(int x){
if(x>=0&&x<60){
System.out.println("小于60分以下的成绩,不及格:"+x);
}
else if(x>=60&&x<80){
System.out.println("大于60分以上的成绩,及格:"+x);
}
else if(x>=80&&x<=100){
System.out.println("大于80分以上的成绩,优良:"+x);
}
else{
System.out.println("输入错误!");
}
}
public static void main(String[] args){
Student stu;
System.out.println("你要输入几个学生的成绩:");
Scanner s=new Scanner(System.in);
int[] arr=new int[s.nextInt()];
System.out.println("请输入学生的成绩:");

for(int i=0;i<arr.length;i++){
stu=new Student(s.nextInt());
System.out.print("第"+(i+1)+"学生的成绩");
moth(stu.score);
}
}
}
rxgp02a 2008-01-10
  • 打赏
  • 举报
回复
输入3个参数,创建你的student对象

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Test {
public static void main(String[] args) {
int[] arr = new int[3];
String temp = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<3;i++) {
try {
System.out.println("请输入第" + (i+1) + "个数字");
temp = br.readLine();
if(temp.matches("\\d+")) {
arr[i] = Integer.parseInt(temp);
}else {
System.out.println("输入错误!");
i--;
}
} catch (IOException e) {
e.printStackTrace();
}
}
Student st = new Student(arr[0],arr[1],arr[2]);
}
}
cursor_wang 2008-01-10
  • 打赏
  • 举报
回复
你的代码乱七八糟,给你写了个.

import java.util.*;
class Student{
int score;
public Student(int k){
this.score=k;
}

public static void moth(int x){
if(x>0&&x<60){
System.out.println("小于60分以下的成绩,不及格:"+x);
}
else if(x>=60&&x<80){
System.out.println("大于60分以上的成绩,及格:"+x);
}
else if(x>=80&&x<=100){
System.out.println("大于80分以上的成绩,优良:"+x);
}
else{
System.out.println("错误!");
}
}
public static void main(String[] args){
Student stu;
Scanner s=new Scanner(System.in);
System.out.println("请输入学生的成绩:");
int[] arr=new int[3];
for(int i=0;i<arr.length;i++){
stu=new Student(s.nextInt());
moth(stu.score);
}
}
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧