Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:31:43+00:00 2026-06-13T08:31:43+00:00

I want to create a small console program which convert from Celsius – Fahrenheit

  • 0

I want to create a small console program which convert from Celsius – Fahrenheit and vice versa, this is the code I tried:

import java.util.Scanner;

public class CelsiusFahrenheit {

    private static Scanner s;

    public static void main(String[] args) {

        s = new Scanner(System.in);
        char reponse = 'N', choixConvert;

        do
        {
            do
            {
                System.out.println("Choisie le mode de converstion : ");
                System.out.println("1 - Converstisseur Celesuis - Fahrenheit");
                System.out.println("2 - Converstisseur Fahrenheit - Celesuis");

                do
                {
                    System.out.print("Votre Choix: ");
                    choixConvert = s.next().charAt(0);
                    if(choixConvert != '1' && choixConvert != '2')
                          System.out.println("Mode inconnu, veuillez réitérer votre choix.");
                }
                while(choixConvert!='1' && choixConvert!='2');

                System.out.print("Température à convertir : ");
                double temp = s.nextDouble();
                System.out.print("Resultat est: " + ConvertCelesuisFahrenheit(choixConvert,temp));
                System.out.println("\nSouhaitez-vous convertir une autre température ? (O/N)");
                reponse = Character.toUpperCase(s.nextLine().charAt(0));

            }while(reponse != 'O' && reponse != 'N');
        }while(reponse == 'O');

        System.out.println("Au revoir !");
    }

    private static Double ConvertCelesuisFahrenheit(int choixConvert,double temp )
    {
        if(choixConvert == 1)
            return (9/5)*temp+32;
        else
            return (temp-32)*(5/9);
    }
}

but I had a problem that the function ConvertCelesuisFahrenheit() always return 0.0 and after that it gives me this error:

Exception in thread “main” java.lang.StringIndexOutOfBoundsException:
String index out of range: 0 at java.lang.String.charAt(Unknown
Source) at CelsiusFahrenheit.main(CelsiusFahrenheit.java:33)

This is the output:

Choisie le mode de converstion : 
1 - Converstisseur Celesuis - Fahrenheit
2 - Converstisseur Fahrenheit - Celesuis
Votre Choix: 2
Température à convertir : 33
Resultat est: 0.0
Souhaitez-vous convertir une autre température ? (O/N)
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(Unknown Source)
    at CelsiusFahrenheit.main(CelsiusFahrenheit.java:33)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:31:44+00:00Added an answer on June 13, 2026 at 8:31 am

    nextDouble() leaves the newline in the input stream, so when you then call

    nextLine().charAt(0)
    

    the result of nextLine() is an empty string. Remove the newline from the stream, or use next(), as you did above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want to create a small program in C# in Windows that would open
I want to create a small function in PHP which takes in arguments like
I want to create a small widget of my website. This widget will facilitate
i want to create functions what get the folder size. I write small function:
I'm learning to do TDD in practice in small project. I want to create
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want to create a small drawing application for children. I do not want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.