Retype the following and run note incorrect behavior Then fi

Re-type the following and run, note incorrect behavior. Then fix errors in the code, which should print numStars asterisks. while (numPrinted 1 = numStars) {System.out.print(\"*\");} import java.util.Scanner; public class StarPrinter {public static void main (String args) {int numStars - theta; int numPrinted = theta; numStars = 12; numPrinted = 1;/* Your solution goes here */System.out.println(\"\"); return;}}

Solution

The required code has been written below:-

-----

//Scanner should be imported for entering the values at run time

import java.util.Scanner;

public class StarPrinter {
  
public static void main(String[] args)
{
//The console asks for the values
  
   System.out.println(\"Please enter the value of numStars\");
   Scanner scan=new Scanner(System.in);
   int numStars=scan.nextInt();
  
   // the inputed value is stored in the numStars variable
  
   System.out.println(\"please enter the value of numPrinted\");
   int numPrinted=scan.nextInt();
  
   // the inputed value is stored in the numPrinted variable
  
   // the while condition checks whether the numbers entered are equal or not
  
   while(numPrinted!=numStars)
   {
         
       System.out.println(\"The Required value is :\"+numStars+\"*\");
       return;
          }
   System.out.println(\"The values given are equal please enter different values \");
   }
}

 Re-type the following and run, note incorrect behavior. Then fix errors in the code, which should print numStars asterisks. while (numPrinted 1 = numStars) {Sy

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site