請撰寫程式,宣告一個變數i,如果i的值小於31,就顯示2的i次方的值。
import java.io.*;
public class ex4_1{
public static void main(String[] argv)
throws IOException{
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
System.out.println("→");
String i = b.readLine();
int y = Integer.parseInt(i);
if(y <=30){
long j = 1;
for(int x = 0;x j = j * 2;
}
System.out.println(j);
}
else {
System.out.println("超出數值,請重新輸入");
}
}
}
import java.io.*;
public class ex4_1{
public static void main(String[] argv)
throws IOException{
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
System.out.println("→");
String i = b.readLine();
int y = Integer.parseInt(i);
if(y <=30){
long j = 1;
for(int x = 0;x
}
System.out.println(j);
}
else {
System.out.println("超出數值,請重新輸入");
}
}
}
全站熱搜
留言列表