import java.util.Scanner;
public class TempConvert {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
//ask the user for a temperature
System.out.println("Enter a temperature:");
double temp = scnr.nextDouble();
//ask the user for the scale of the temperature
System.out.println("Is that Fahrenheit (F) or Celsius (C)?");
char choice = scnr.next().charAt(0);
if(choice == 'F') {
//convert to Celsius if given temperature was Fahrenheit
System.out.println(temp + " degrees Fahrenheit is " + ((5.0/9) *
(temp-32)) + " degrees Celsius");
} else {
//convert to Fahrenheit if given temperature was Celsius
System.out.println(temp + " degrees Celsius is " + (((9*temp)/5) +
32) + " degrees Fahrenheit");
}
}
}
How do I fix this code to have the output be rounded rather than long decimals. Like 35.6 over 35.555555559 if that makes sense. I don't know how to fix it within the code. That's the only thing that's wrong.
import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //ask the user for a temperature System.out.println("Enter a temperature:"); double temp = scnr.nextDouble(); //ask the user for the scale of the temperature System.out.println("Is that Fahrenheit (F) or Celsius (C)?"); char choice = scnr.next().charAt(0); if(choice == 'F') { //convert to Celsius if given temperature was Fahrenheit System.out.println(temp + " degrees Fahrenheit is " + Math. round(((5.0/9) * (temp-32)) * 100.0) / 100.0 + " degrees Celsius"); } else { //convert to Fahrenheit if given temperature was Celsius System.out.println(temp + " degrees Celsius is " + Math. round((((9*temp)/5) + 32) * 100.0) / 100.0 + " degrees Fahrenheit"); } } }
import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new...
import java.util.Scanner; public class Lab6d { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); // TODO: get user choice // TODO: call printTable method passing choice as the parameter } public static void printTable(int stop) { // TODO: print header // TODO: loop to print table rows up to stop value } Write a Java program where the main () method prompts the user to select an integer value between 1 and...
import java.util.Scanner; public class TriangleMaker { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle."); Scanner keyboard = new Scanner(System.in); int size = keyboard.nextInt(); for (int i = 1; i <= size; i++) { for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } for (int...
import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 { public static void main(String[] args) { String name; String answer; int correct = 0; int incorrect = 0; Scanner phantom = new Scanner(System.in); System.out.println("Hello, What is your name?"); name = phantom.nextLine(); System.out.println("Welcome " + name + "!\n"); System.out.println("My name is Danielle Brandt. " +"This is a quiz program that...
import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...
Fix this program package chapter8_Test; import java.util.Scanner; public class Chapter8 { public static void main(String[] args) { int[] matrix = {{1,2},{3,4},{5,6},{7,8}}; int columnChoice; int columnTotal = 0; double columnAverage = 0; Scanner input = new Scanner(System.in); System.out.print("Which column would you like to average (1 or 2)? "); columnChoice = input.nextInt(); for(int row = 0;row < matrix.length;++row) { columnTotal += matrix[row][columnChoice]; } columnAverage = columnTotal / (float) matrix.length; System.out.printf("\nThe average of column %d is %.2f\n", columnAverage, columnAverage); } } This program...
please debug this code: import java.util.Scanner; import edhesive.shapes.*; public class U2_L7_Activity_Three{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); double radius; double length; System.out.println("Enter radius:"); double r = scan.nextDouble(); System.out.println("Enter length:"); double l = scan.nextDouble(); System.out.println("Enter sides:"); int s = scan.nextInt(); Circle c = Circle(radius); p = RegularPolygon(l , s); System.out.println(c); System.out.println(p); } } Instructions Debug the code provided in the starter file so it does the following: • creates two Double objects named radius and length creates...
import java.util.Scanner; public class Client{ public static void main(String args[]){ Coin quarter = new Coin(25); Coin dime = new Coin(10); Coin nickel = new Coin(5); Scanner keyboard = new Scanner(System.in); int i = 0; int total = 0; while(true){ i++; System.out.println("Round " + i + ": "); quarter.toss(); System.out.println("Quarter is " + quarter.getSideUp()); if(quarter.getSideUp() == "HEADS") total = total + quarter.getValue(); dime.toss(); System.out.println("Dime is " + dime.getSideUp()); if(dime.getSideUp() == "HEADS") total = total +...
import java.util.Scanner; public class MPGMain { public static void main(String[] args) { Scanner input = new Scanner(System.in); Mileage mileage = new Mileage(); System.out.println("Enter your miles: "); mileage.setMiles(input.nextDouble()); System.out.println("Enter your gallons: "); mileage.setGallons(input.nextDouble()); System.out.printf("MPG : %.2f",mileage.getMPG()); } } public class Mileage { private double miles; private double gallons; public double getMiles()...
import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables int creditScore; double loanAmount,interestRate,interestAmount; final double I_a = 5.56,I_b = 6.38,I_c = 7.12,I_d = 9.34,I_e = 12.45,I_f = 0; String instructions = "This program calculates annual interest\n"+"based on a credit score.\n\n"; String output; Scanner input = new Scanner(System.in);// for receiving input from keyboard // get input from user System.out.println(instructions ); System.out.println("Enter the loan amount: $"); loanAmount = input.nextDouble(); System.out.println("Enter the credit score: "); creditScore...
make this program run import java.util.Scanner; public class PetDemo { public static void main (String [] args) { Pet yourPet = new Pet ("Jane Doe"); System.out.println ("My records on your pet are inaccurate."); System.out.println ("Here is what they currently say:"); yourPet.writeOutput (); Scanner keyboard = new Scanner (System.in); System.out.println ("Please enter the correct pet name:"); String correctName = keyboard.nextLine (); yourPet.setName (correctName); System.out.println ("Please enter the correct pet age:"); int correctAge = keyboard.nextInt (); yourPet.setAge (correctAge); System.out.println ("Please enter the...