0% found this document useful (0 votes)
0 views

Activity-Software-Defect

The document contains a Java program that prompts the user to enter a number and demonstrates the use of for and while loops. There are syntax errors and logical issues in the code, such as missing semicolons and incorrect loop conditions. The program also allows the user to repeat the process by asking if they want to try again.

Uploaded by

Jay Cee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Activity-Software-Defect

The document contains a Java program that prompts the user to enter a number and demonstrates the use of for and while loops. There are syntax errors and logical issues in the code, such as missing semicolons and incorrect loop conditions. The program also allows the user to repeat the process by asking if they want to try again.

Uploaded by

Jay Cee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;
public class forandwhile{
public static void main(String[] args) {
Scanner input = new Scanner(System.in)

int counter1,counter2
int numb

char ANS='y';

while (ANS == 'y')


{
System.out.println("Enter the number: ");
number = input.next();

// using for loop


System.out.println("Using for loop");

for (counter1 = 1; counter1 <=number; counter1 --)


{
/*for (counter1 = 1; counter1 <=counter2; counter2--)
{
System.out.print(counter2 + " "); }
System.out.println(""); // go to the next line
}*/

// using while loop


System.out.println(" ")
System.out.println("Using While Loop")

counter1 = 5; // initialize counter1


while (counter1 <= number)
{
counter1 = 1; //initialize counter1

{
System.out.print(counter1+" ");
counter1--;
}
counter1--; // increment counter1
System.out.println(" "); // go to the next line
}
System.out.print("Try again ? ");
ANS = input.next().charAt(0);
}
}
}

You might also like