2 の乗数(2^0,2^1・・)を 2 の 10 乗まで出力するプログラム
コード
import java.util.Scanner;
public class Program {
public void input (){
Scanner scan = new Scanner (System.in);
}
public void compute(){
}
public void output (){
for(int i = 0;i<=10;i++){
System.out.println(2^i);
}
}
public static void main (String[] args){
Program p = new Program ();
p.input();
p.compute();
p.output();
}
}
出力
[Sample Input----------]
[----------------------]
[Program Output--------]
2
3
0
1
6
7
4
5
10
11
8
[----------------------]
出力が間違っているのですが、こうなった原因がわかりません
System.out.println(2^i);の部分を間違ったのは分かったのですが、for文を使った形で累乗はどうやるのですか?
回答1件
あなたの回答
tips
プレビュー