0% found this document useful (0 votes)
14 views2 pages

Java Lab 7

The document provides instructions for a Java lab assignment, requiring the creation of a Java file named 'lab7' and the implementation of a program using while loops. The program must count from 1 to 10, count down from 10 to 1, and repeatedly divide a user-input integer by two until the result is 1. It emphasizes the need for a counter variable, a valid loop condition, and a method to modify the counter within the loop.

Uploaded by

arya.santosh2007
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)
14 views2 pages

Java Lab 7

The document provides instructions for a Java lab assignment, requiring the creation of a Java file named 'lab7' and the implementation of a program using while loops. The program must count from 1 to 10, count down from 10 to 1, and repeatedly divide a user-input integer by two until the result is 1. It emphasizes the need for a counter variable, a valid loop condition, and a method to modify the counter within the loop.

Uploaded by

arya.santosh2007
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/ 2

Java Lab 7

 Create a new Java file (empty Java file), save it to your H: drive, call it lab7
 Insert the following code to set up your program:

import java.util.Scanner;

public class lab7 {

public static void main (String args[]){

Scanner input = new Scanner(System.in);

100pt:

Write a program using while loops that accomplishes the following:

 Counts from 1 to 10
 Counts down from 10 to 1
 The user inputs an integer. The program will divide that number by two repeatedly until the
answer is 1. Your program output should appear as follows:

Input an integer:

>> 200

200 / 2 = 100
100 / 2 = 50
50 / 2 = 25
25 / 2 = 12
12 / 2 = 6
6 / 2 = 3
3 / 2 = 1
Notes:

Be sure that your while loop contains the following:

 “Counter” variable created before the loop


 A valid condition (double check your > or < signs)
 A way to decrease or increase the counter variable inside the loop

For example:

int i = 1;

while(i < 5){

System.out.println(i);

i++;

You might also like