import java.util.Scanner;
public class putin
{
public static void main(String[] args)
Scanner s = new Scanner(System.in);
System.out.println("現在可以輸入一個數字。整數或者是小數:");
int i = 0;
int x = 0;
int y = 0;
while(s.hasNext())
i++;
if( 1 == i)
x = s.nextInt();
}
if( 2 == i)
y = s.nextInt();
System.out.println("加法:"+(x+y));
System.out.println("減法:"+(x-y));
System.out.println("乘法:"+(x*y));
System.out.println("除法:"+((double)x/(double)y));
你可能不知道怎麼用Scanner
看你不會的份上 我給你寫出一個!
import java.util.Scanner;
public class putin
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("現在可以輸入一個數字。整數或者是小數:");
int i = 0;
int x = 0;
int y = 0;
while(s.hasNext())
{
i++;
if( 1 == i)
{
x = s.nextInt();
}
if( 2 == i)
{
y = s.nextInt();
System.out.println("加法:"+(x+y));
System.out.println("減法:"+(x-y));
System.out.println("乘法:"+(x*y));
System.out.println("除法:"+((double)x/(double)y));
}
}
}
}
你可能不知道怎麼用Scanner
看你不會的份上 我給你寫出一個!