Use the isPrime method that you wrote in previous question in a program that stores a list of all the prime numbers from 1 through 100 in a file. this was the previous question ?
can you plz make it so i can copy and past
and can you plz make it in java.util.scanner
Use the isPrime method that you wrote in previous question in a
stores a list of all the prime numbers from 1 through 100 in a file.
this was the previous question ?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package milimil;
import java.util.Scanner;
/**
*
* @author Mabda
*/
public class Milimil {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int selection;
double distance;
Scanner key = new Scanner(System.in);
do
{
System.out.print("Enter a positive distance in meters: ");
distance = key.nextDouble();
}while(distance <= 0);
do
{
menu();
System.out.print("\nEnter your choice 1 through 4 by typing a number: ");
selection = key.nextInt();
while (selection < 1 || selection > 4)
{
System.out.print("Invalid selection. Enter your choice: ");
selection = key.nextInt();
}
switch (selection)
{
case 1 : metersToKilometers(distance);
break;
case 2 : metersToInches(distance);
break;
case 3 : metersToFeet(distance);
break;
case 4 : System.out.println("Bye!");
}
System.out.println();
} while (selection != 4);
}
public static void menu()
{
System.out.println("1. Convert to kilometers");
System.out.println("2. Convert to inches");
System.out.println("3. Convert to feet");
System.out.println("4. Quit the program");
}
public static void metersToKilometers(double meters)
{
double kilometers = meters * 0.001;
System.out.println(meters + " meters is " +
kilometers + " kilometers.");
}
public static void metersToInches(double meters)
{
double inches = meters * 39.37;
System.out.println(meters + " meters is " +
inches + " inches.");
}
public static void metersToFeet(double meters)
{
double feet = meters * 3.281;
System.out.println(meters + " meters is " +
feet + " feet.");
}
}
Step by step
Solved in 2 steps