andrew771027 10 發表於 February 28, 2008 檢舉 Share 發表於 February 28, 2008 我是一個大學生最近學校開始教JAVA前幾天出了一份作業,總共有兩題第一題我寫出來了,很高興但是第二題只寫出一半來請大大幫忙指導一下,我是認為沒有錯阿,怎麼還不為給過?題目是這樣Write a program that inputs five numbers and determines and prints the numberof negative numbers input, the number of positive numbers input and thenumber of zeros input.我做的第一部份是/** * @(#)TEST2.java * * TEST2 application * * @author * @version 1.00 2008/2/27 */import java.util.Scanner;public class TEST2 { public static void main(String[] args) { Scanner input=new Scanner(System.in); int number; for(int i=1 ; i<=5 ; i++) { System.out.println("請輸入一個整數"); number = input.nextInt(); if(number>0) { System.out.println("你輸入的整數為正整數\n謝謝"); } if (number<0) { System.out.println("你輸入的整數為負整數\n謝謝"); } if (number==0){ System.out.println("你輸入的整數為零\n謝謝"); } } // TODO, add your application code }}COMPILE給過了可是加了第二部份,卻/** * @(#)TEST2.java * * TEST2 application ** @author * @version 1.00 2008/2/27 */ import java.util.Scanner;public class TEST2 { public static void main(String[] args) { Scanner input=new Scanner(System.in); int number; int a=0,b=0,c=0; for(int i=1 ; i<=5 ; i++) { System.out.println("請輸入一個整數"); number = input.nextInt(); if(number>0) { System.out.println("你輸入的整數為正整數\n謝謝"); ++a; } if (number<0) {System.out.println("你輸入的整數為負整數\n謝謝"); ++b; } if (number==0) { System.out.println("你輸入的整數為零\n謝謝"); ++c; } } System.out.println("你輸入了%d個正整數",a); System.out.println("你輸入了%d個負整數",b); System.out.println("你輸入了%d個零",c); // TODO, add your application code }}COMPILE卻不給過反而出現了cannot find symbol method println(java.lang.String,int) line37 38 39COMPILE卻不給過反而出現了cannot find symbol method println(java.lang.String,int) line37 38 39我不知道這句錯誤訊息是什麼意思,要如何修正呢?謝謝 鏈接文章 分享到其他網站
johnroyer 10 發表於 March 5, 2008 檢舉 Share 發表於 March 5, 2008 改成System.out.println("你輸入了" + a + "個正整數");不然用 printfSystem.out.printf("你輸入了%d個正整數",a); 鏈接文章 分享到其他網站
Recommended Posts
請登入後來留意見
在登入之後,您才能留意見
立即登入