2007-10-23 11:26:49maple 

JAVA第二堂程式



import java.util.Scanner;

public class Addition
{

public static void main(String args[])

{

Scanner input=new Scanner(System.in);

int a,
b,
sum;

System.out.print(”請輸入一個整數”);
a=input.nextInt();

System.out.print(”請輸入兩個整數”);
b=input.nextInt();

sum=a+b;

System.out.printf(”加總結果為 %d%n”,sum);

if(sum>=0)
System.out.printf(”%d是一個正整數%n”,sum);

if(sum<=0)
System.out.printf(”%d是一個負整數%n”,sum);

}

}



import java.util.Scanner;

public class Addition
{

public static void main(String args[])

{

Scanner input=new Scanner(System.in);

int a,


System.out.print(”請輸入一個整數”);
a=input.nextInt();


if(a==123)
System.out.printf(”恭喜你猜對了n”);

if(sum!=123)
System.out.printf(”喔~你猜錯了!n”);

}

}