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

Java Lab 8

The document outlines a Java lab assignment where students must create a program to find the largest and smallest factors of a number and determine if the number is prime. It provides a basic code structure and hints on using while loops and modulus operations. An example interaction with the program is also included to illustrate expected output.

Uploaded by

arya.santosh2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java Lab 8

The document outlines a Java lab assignment where students must create a program to find the largest and smallest factors of a number and determine if the number is prime. It provides a basic code structure and hints on using while loops and modulus operations. An example interaction with the program is also included to illustrate expected output.

Uploaded by

arya.santosh2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Lab 8

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

import java.util.Scanner;

public class lab8 {

public static void main (String args[]){

Scanner input = new Scanner(System.in);

100pt:

Write a program using while loops to:

 Discover the largest factor of a number


 Discover the smallest factor of a number
 Tells you if the number is prime (i.e. it has no factors other than 1 and itself)

Hints:

 A factor is a number that evenly divides into another (for instance, the factors of 10 are 1, 2, 5, 10). In
other words, factors are numbers that you can multiply together to get another.
 Remember modulus (%) that returns the remainder of a division (i.e. 12 % 5 == 2)

Example program:

>> Please enter a number to discover the largest and smallest factors of:

>>> 24

>> Largest Factor: 12

>> Smallest Factor: 2


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