자바 while문에서 for문으로ㅠ
-
게시물 수정 , 삭제는 로그인 필요
자바에서 while문을 for문으로 작성하는건데요.
문제 >>>> input(a Scanner)은 이전에 선언되었다고 가정한다.
a. .
int count = 0;
int sum = 0;
while(count<10)
{
sum += input.nextInt();
count = count+1;
}
이거하고
b.
int count =1 ;
while (count<=15)
{
int num=1;
int sum=0;
while ( num<=5)
{
sum+=input.nextInt();
num +=1;
}
System.out.println("sum number" + count + "is" + sum);
count++;
}
이거입니다ㅠㅠ
근데 a문제 푸는데 일단 while문으로 돌려보려고 제가 코드를 짯는데 실행이 안되네요ㅠㅠ무슨 오류죠
import java.util.Scanner;
public class dddd {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int count = 0;
int sum = 0;
while(count<10)
{
sum += input.nextInt();
count = count+1;
}
System.out.print("sum");
}
}
잘못된거랑.. 답좀 알려주시면 감사하겟습ㄴ디ㅏㅏㅠㅠ
자바에서 while문을 for문으로 작성하는건데요.
문제 >>>> input(a Scanner)은 이전에 선언되었다고 가정한다.
a. .
int count = 0;
int sum = 0;
while(count<10)
{
sum += input.nextInt();
count = count+1;
}
이거하고
b.
int count =1 ;
while (count<=15)
{
int num=1;
int sum=0;
while ( num<=5)
{
sum+=input.nextInt();
num +=1;
}
System.out.println("sum number" + count + "is" + sum);
count++;
}
이거입니다ㅠㅠ
근데 a문제 푸는데 일단 while문으로 돌려보려고 제가 코드를 짯는데 실행이 안되네요ㅠㅠ무슨 오류죠
import java.util.Scanner;
public class dddd {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int count = 0;
int sum = 0;
while(count<10)
{
sum += input.nextInt();
count = count+1;
}
System.out.print("sum");
}
}
잘못된거랑.. 답좀 알려주시면 감사하겟습ㄴ디ㅏㅏㅠㅠ