我想問怎麼把下面的程式
改成傳入兩個參數(學制和成績)後,判斷出答案
若學制是"M"開頭印出碩士,碩士70分及格;
"A"開頭印出學士,學士60分及格
import java.lang.*;
public class J1005_6
{
public static void main(String args[])
{
String num="M950000";
int I=70;
if (num.charAt(0)=='M')
if (I>=70)
System.out.println("碩士及格");
else
System.out.println("碩士,不及格");
else
if (I>=60)
System.out.println("學士及格");
else
System.out.println("學士,不及格");
}
}
2007-10-18 06:05:24 · 2 個解答 · 發問者 Jane 2 in 電腦與網際網路 ➔ 程式設計
import java.lang.*;
import java.util.*; \\Scanner所在位置
public class J1005_6
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("請輸入學制");
String num=sc.next();
System.out.println("請輸入分數");
int I=sc.nextInt();
if (num.charAt(0)=='M')
if (I>=70)
System.out.println("碩士及格");
else
System.out.println("碩士,不及格");
else
if (I>=60)
System.out.println("學士及格");
else
System.out.println("學士,不及格");
}
}
2007-10-18 08:20:52 · answer #1 · answered by ? 3 · 0⤊ 0⤋
import java.io.*;
import java.util.*;
public class TEST
//檔名:TEST.java
{
public static void main(String[] args)
{
PrintStream o=new PrintStream(System.out);
Scanner in=new Scanner(System.in);
o.printf("碩士(M)?: ");
String m=in.next();
o.printf("分數?: ");
int l=in.nextInt();
o.printf("%s\n",res(m.charAt(0),l));
}
public static String res(char ch, int g)
{
ch+=(ch<97?0:-32);
return (ch=='M'?(g<70?"碩士不及格":"碩士及格"):(g<60?"學士不及格":"學士及格"));
}
}
2007-10-18 18:47:42 · answer #2 · answered by Big_John-tw 7 · 0⤊ 0⤋