close
題目概要:
輸入2個整數,求出2整數間有多少平方項。
解題方向:
取最小整數開根號的值i,從i開始算平方,直到i平方大於b時停止,在輸出結果。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java | |
import java.util.Scanner; | |
class uva11461{ | |
public static void main(String args[]){ | |
Scanner sc=new Scanner(System.in); | |
int a=0; | |
int b=0; | |
while((a=sc.nextInt())!=0 && (b=sc.nextInt())!=0){ | |
int count=0; | |
int i=(int)Math.sqrt(a); | |
while((int)Math.pow(i,2)<=b){ | |
if((int)Math.pow(i,2)>=a) count++; | |
i++; | |
} | |
System.out.println(count); | |
} | |
} | |
} |
文章標籤
全站熱搜