Home > Software engineering >  Im trying to declare a variable named num1 of the data type byte that is assigned the value 2, Conca
Im trying to declare a variable named num1 of the data type byte that is assigned the value 2, Conca

Time:09-30

I need to print out "Num 1 is: 2" on the terminal, and I'm having some trouble

this is what I've tried when every I run it it comes out as

Num 1 is:

2

and I just can get it to show as Num 1 is: 2

public class JavaVariables3
{
  public static void main(String[]args)
{
  byte num1;
  num1 =2;

  System.out.println("Num 1 is:");
  System.out.println(num1);
}

CodePudding user response:

System.out.println() Will print your text and then a newline. If you don't want a new line, use System.out.print() instead:

public class JavaVariables3
{
    public static void main(String[]args)
    {
        byte num1;
        num1 =2;

        System.out.print("Num 1 is:");
        System.out.println(num1);
}

Or using concatenation:

public class JavaVariables3
{
    public static void main(String[]args)
    {
        byte num1;
        num1 =2;

        System.out.println("Num 1 is:"   num1);
    }
}
  •  Tags:  
  • java
  • Related