Search This Blog

Wednesday, December 14

!ANSWER! Assignment 1

Below you will find my answer to last week's Java assignment.

Hope this helps!

import java.awt.Choice;
import java.util.*;

public class BajrovicAssignment1 {
	public static void main(String[] args){
		Scanner in = new Scanner(;
		String[] menu = new String[4];
		menu[0] = "Please choose an option for temperture conversion below:";
		menu[1] = "1: Fahrenheit to Celsius";
		menu[2] = "2: Celsius to Fahrenheit";
		menu[3] = "x: Exit";
	for (String m : menu)	//prints the entire array with only 1 system.out 
	String choice = in.nextLine();
	if (choice.equals("1")){
		System.out.println("What Fahrenheit temperature would you like to convert?");
		float Fahrenheit = in.nextFloat();
		float Celsius = (Fahrenheit-32)*5/9;
	else if (choice.equals("2")){
		System.out.println("What Celsius temperature would you like to convert?");
		float Celsius = in.nextFloat();
		float Fahrenheit = Celsius*9/5+32;
	else if (choice.equals("x")){
				System.out.println("Invalid Selection.");
How did you solve it? What could I have done differently?

No comments:

Post a Comment