Skip to content

Error in the code of the program #3

@Adwaithanil05

Description

@Adwaithanil05

public class SwapNumbers
{
public static void main(String[] args)
{

    float first = 1.20f, second = 2.45f;

    System.out.println("--Before swap--");
    System.out.print("First number = " + first); //Semi-colon added 
    System.out.println("Second number = " + second);

    // Value of first is assigned to temporary
    float temporary = first;

    // Value of second is assigned to first
    first = second; //Semi-colon added

    // Value of temporary (which contains the initial value of first) is assigned to second
    second = temporary; //Removed the + symbol

    System.out.println("--After swap--");
    System.out.println("First number = " + first);
    System.out.println("Second number = " + second);
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions