0
Hey can you please tell me what I did wrong?
I have to create a program in java with ,,do while, for” , and the output has to be all even-numbers ,,2,4,6,8...n”. { int n,d,b,i=0; for(b=1;i<=n;b++) { d=2; while((d<b)&&(d%b!=0)) d++; if (d==b) { cout <<b; i+=1; } } }
3 odpowiedzi
+ 2
Hello Ariadna Topala
cout << is c++ not java.
In java you have to use System.out.print() or System.out.println().
0
so what should I do? I tried changing it but it gave me error
0
//System.out.println("Enter the number : ");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
///////////////////// with for loop ;
System.out.println("with for loop");
for(int i =1 ;i<=n ; i++) {
if(i%2==0)System.out.println(i);
}
//////////////////// withe do while loop ;
System.out.println("with do while loop");
int i = 1 ;
do{if(i%2==0)System.out.println(i);
i++;
}
while(i<=n);