Java程序错误,用于编译该程序

时间:2019-05-21 09:32:04

标签: java java.util.scanner lcm

`
package com.company;
import java.util.Scanner;
public class Main
{
    public static void main(String args[])
    {
        int hcf , lcm , t;
        Scanner ghostScanner =  new Scanner (System.in);
        System.out.println("to c



alculate hcd and lcm \nhit in both the no.s ");
        int number1 = ghostScanner.nextInt();
        int number2 = ghostScanner.nextInt();
        System.out.println("> To calculate hcf of the numbers hit '1' \n>To calculate lcm of the numbers hit '2' \n>To calculate both hit '3'");
        int choice = ghostScanner.nextInt();
        while (number2 != 0)
        {
            t = number2;
            number2 = number1 % number2;
            number1 = t;
        }
        hcf = number1;
        lcm = (number1*number2) / hcf;
        if (choice == 1)
        {
            System.out.println("hcf of " + (number1) " and " + (number2) + " is " + (hcf));
        }
        else if (choice == 2)
        {
            System.out.println("lcm of " + number1 " and " + number2 + " is " + lcm);
        }
        else if (choice == 3)
        {
            System.out.println(" the hcf and lcm of " + number1 + " and " + number2 + " is " + hcf + " and " + lcm + " respectively \nthanx for staying with us \n:)");
        }
        else if (choice == 0)
        {
            System.out.println("KeyboardInterruptError");
        }


    }

}
`

我知道这是基本代码...但是我不知道为什么编译时会出错。错误是奇怪的“ java.util.Scanner已弃用”,number1甚至不是一个类,但错误消息显示类似内容。您能帮我解决代码中的问题吗。。thanx

1 个答案:

答案 0 :(得分:1)

+ is missing between number1 and " in the below System.out.println() statements

if (choice == 1){
      System.out.println("hcf of " + (number1) " and " + (number2) + " is " + (hcf));
}else if (choice == 2){
      System.out.println("lcm of " + number1 " and " + number2 + " is " + lcm);
 }