-5

I am doing my first Java assignment and I'm struggling with an error here.

 * 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 ctof;

/**
 *
 * @author Braydon
 */
    import java.util.Scanner;
public class CtoF {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Enter temperature in Celsius:");
        Scanner temp = new Scanner(System.in);
        String T = scan.nextLine();
            T = (T - 32) * 5/9;
            System.out.println("Temperature in Fahrenheit =" + T);
             }
}

The error it gives me is as follows.

run:
Enter temperature in Celsius:
Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
    at ctof.scan.nextLine(scan.java:19)
    at ctof.CtoF.main(CtoF.java:21)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

The error is in the line where I perform the math, but I've tried everything and I can't seem to fix it. Please help!

2 Answers2

1

You're calling the wrong function.

You need to call temp.nextLine() instead of scan.nextLine() in order to read the next line. (scan isn't even defined in the code you posted)

HOWEVER: You shouldn't use nextLine() when you need to read a number.

Therefore: Call temp.nextInt() or temp.nextDouble() instead.

Aify
  • 3,543
  • 3
  • 24
  • 43
0

I believe you are newbie to java. First of all, you will have to learn about the data types. Well, you can google basics about programming and learn from it.

The solution for your problem :

public class CtoF {

    public static void main(String[] args) {
        System.out.println("Enter temperature in Celsius:");
        Scanner temp = new Scanner(System.in);
        int T = temp.nextInt();
        T = (T - 32) * 5 / 9;
        System.out.println("Temperature in Fahrenheit =" + T);
    }
}

Try to use good names for the variables (just a suggestion)

Roshan Shahukhal
  • 243
  • 4
  • 15
  • Thanks for all the help people. I have the code functional now, but my math is wrong so I need to go back and figure out what I'm doing wrong with the order of operations or something. – Braydon Rekart Sep 16 '15 at 20:00
  • If you think this is the correct answer, mark it as the one.. it really motivates us to answer to the questions ! And glad to hear that it's solved, have fun coding ! – Roshan Shahukhal Sep 16 '15 at 20:02
  • I marked it, but it won't show up until I get 15 positive votes. Seems my inquiry got -5 marked off so it will take me a while. – Braydon Rekart Sep 16 '15 at 20:09