Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java while loop problem. How to write while and print statement part of pic2? Th

ID: 3795577 • Letter: J

Question

Java while loop problem.

How to write while and print statement part of pic2? Thx.

a public class Number operations private int number 4 public Number Operations (int number In) number number In 8 public int getValue return number 10 11 public String odds Under 12 String output int i 0; 13 while (i number) 14 if (i 2 0) 15 output i t"; 16 17 i++; 18 19 20 return output 21 22 public string powers Two Under String output 23 int powers 1; 24 while (powers number) 25 output powers "lt"; 26 powers powers 2 28 29 return output 30 31 public int is (int compare Number) f Greater 32 if (number compareNumber) 33 return 1 34 else if (number er 35 36 return -1; 37 38 else 39 return 0; 40 41 42 public String toString return number 43 44 45

Explanation / Answer

while(input !=0)
{
numOpsList.add(input); //adding elements to lst
input=in.nextInt();
}

for(int i=1;i<=num;i++){
   if((i%2 )!==0)
   System.out.println("The number under"+num+" ,"+i+"is odd");
   System.out.println("The powers of 2 under number "+num+"is 2^"+math.log2(i) );
   }

//math.log2(num) returns the power of 2 value of that number,ie.math.log2(4) returns 2.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote