Java Program for Fahrenheit and Celsius Conversion with Menu Options

  • Comp Sci
  • Thread starter ritwik06
  • Start date
  • Tags
    Java Program
In summary, to solve the given problem, you can use the Integer.parseInt() method to convert the ASCII value of the choice entered by the user to an integer. This will allow you to successfully perform the desired conversion between Fahrenheit and Celsius temperatures in your program.
  • #1
ritwik06
580
0

Homework Statement


Write a program to calculate the Fahrenheit temperature from Celsius Temperature and vice Versa using appropriate menu.

2. The attempt at a solution

class prog
{
static void choice(String args[])
throws java.io.IOException
{
int choice=0;
System.out.print("Enter 1 to Change F to c");
System.out.print("Enter 2 to Change c to F");
choice=System.in.read();

---------
----
---
--
Problem
This thing give me the ASCII value of th choice I enter. How to convert it to Integer? Pleas do hlp soon.
 
Last edited:
Physics news on Phys.org
  • #2
You can use the Integer.parseInt() method to convert the ASCII value to an int. Here is an example: int choice = Integer.parseInt(System.in.read());
 
  • #3




Hello, it seems like you are trying to convert a character input into an integer. To do this, you can use the Character.getNumericValue() method. This method takes in a character and returns its numeric value as an integer. In your case, you can use it like this:

choice = Character.getNumericValue(choice);

This will convert the character value of the choice variable into its corresponding integer value. I hope this helps. Good luck with your program!
 

What is a Java program?

A Java program is a set of instructions written in the Java programming language that can be executed by a computer. It typically consists of classes, methods, and variables that work together to perform a specific task.

What is a simple Java program?

A simple Java program is a program that performs a basic task with minimal code. It may include basic input/output, arithmetic operations, and conditional statements.

How do I write a very simple Java program?

To write a very simple Java program, you will need a text editor to write your code and a Java compiler to convert the code into a format that can be executed by a computer. The basic structure of a simple Java program consists of a class with a main method, where the program's instructions are written.

What are the benefits of learning Java programming?

Learning Java programming can have many benefits, including the ability to create applications for personal or professional use, understanding the fundamentals of object-oriented programming, and gaining valuable problem-solving and critical thinking skills.

Are there any resources available for learning how to write a simple Java program?

Yes, there are numerous resources available for learning how to write a simple Java program. These include online tutorials, textbooks, and coding bootcamps. Many universities and community colleges also offer courses on Java programming.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
25
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
16
Views
12K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
17K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
Back
Top