Java程式問題~不太會寫或修改(新手上路),請大大協助幫忙!
願有心幫助的java高手們,能幫新手的我寫出(修改)完整的程式,
並且可以run出結果,供我日後能參照學習!衷心感謝!
1.輸入N(1<N<100)名學生的英文成績,求出英文成績中的最高分數。
範例輸入 :
80 70 60 90 50
範例輸出 :
90
我有爬文找到這個類似的,可是不知怎麼修改
import java.util.*;
public class MaxScore {
public static void main(String[] args) {
System.out.print("請輸入學生人數: ");
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int[] grades = new int[N];
int max = -1, min = 101, sum = 0, passed = 0;
for (int i = 0; i < N; i++) {
System.out.print("請輸入第" + (i+1) + "位學生成績: ");
grades = scan.nextInt();
if (grades > max) max = grades;
if (grades < min) min = grades;
if (grades >= 60) passed++;
sum += grades;
}
System.out.println("本班最高分數: " + max + "分");
System.out.println("本班最低分數: " + min + "分");
System.out.println("本班及格人數: " + passed + "人");
System.out.println("本班期末考總平均: " + sum * 100 / N / 100.0D);
}
}
2.輸入一個整數 n (>=3)使用迴圈顯示以下圖形。
範例輸入 :
>java SquareStars 5
範例輸出 :
*****
* *
* *
* *
*****
我有爬文找到這個類似的,可是不知怎麼修改
public class SquareStars {
public static void main(String[] args) {
int A = Integer.parseInt(args[0]);
for (int i=1; i<=A; i++)
{
if(i==1 || i==A)
{
for (int j=1 ; j<=A ; j++)
{
System.out.print('*');
}
}else
{
for (int j=1 ; j<=A ; j++)
{
if(j==1 || j==A)
{
System.out.print('*');
}
else
{
System.out.print(' ');
}
}
}
System.out.println();
}
}
}
或是
public class Main {
public static void main(String[] args) {
if(args.length==0){
System.out.println("請輸入參數");
}else{
if(Integer.valueOf(args[0])<3){
System.out.println("參數至少為3");
}else{
for(int i=1;i<=Integer.valueOf(args[0]);i++){
if(i==1||i==Integer.valueOf(args[0])){
System.out.println("*****");
}else{
System.out.println("* *");
}
}
}
}
}
}
或是
public class homework1 {
public static void main(String[] args) {
String stars= "***********"; //11個
String spaces=" ";
for (int i=0; i <=5; i++)
System.out.println(spaces.substring(0,i) + stars.substring(2*i));
for (int i=4; i>=0; i--)
System.out.println(spaces.substring(0,i) + stars.substring(2*i));
}
}
3.以下為常用的兩種日期格式 4/25/1955 和 April 25,1955 ,撰寫一個程式,能夠讀入第一種格式的日期字串, 並以第二種格式列印出來。
( 月份英文: January, February , March, April, May, June, July, August, September, October, November, December )
範例輸入 :
4/25/1955
範例輸出 :
April 25,1955
我有爬文找到這個類似的,可是不知怎麼修改
import java.util.Date;
import java.util.Locale;
public class Translate {
public static void main(String[] args) {
Date date = new Date (args[0]);
Locale locale = new Locale("en","US");
System.out.println(String.format(locale,"%1$tB,%1$tD,%1$tY", date));
}
}
請大大謝協助幫忙!感激不盡!
[ 本帖最後由 9319074 於 2010-8-26 13:11 編輯 ]