Scanner sc = new Scanner(System.in);
System.out.print("Enter number \n");
int num = sc.nextInt();
System.out.print("number : " + num + "\n");
System.out.print("Enter line \n");
String s = sc.nextLine();
System.out.print("line : " + s + "\n");
In the following code snippet, the program reads input from the console. However, if the user enters characters instead of the expected data type, will it still work as intended?
Scanner sc = new Scanner(System.in);
System.out.println("Enter number");
int num = sc.nextInt();
System.out.println("number : " + num);
Tech-Bimba (ಬಿಂಬ)
is the following code snippet works fine ?
Scanner sc = new Scanner(System.in);
System.out.print("Enter number \n");
int num = sc.nextInt();
System.out.print("number : " + num + "\n");
System.out.print("Enter line \n");
String s = sc.nextLine();
System.out.print("line : " + s + "\n");
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
In the following code snippet, the program reads input from the console.
However, if the user enters characters instead of the expected data type, will it still work as intended?
Scanner sc = new Scanner(System.in);
System.out.println("Enter number");
int num = sc.nextInt();
System.out.println("number : " + num);
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
Scanner sc = new Scanner(System.in);
int a = sc.hasNextInt();
is the mentioned code snippet is correct ?
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
Is the following statement correct :
Primitive data types have a fixed size, whereas non-primitive data types do not have a predetermined size.
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
To read input from console what is correct way of creating the Scanner class object.
a> Scanner sc = new Scanner(System.in);
b> Scanner sc = new Scanner(System.out);
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
What is the output of the following code snippet?
boolean flag = true;
System.out.println(!flag );
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
Bitwise operators are faster than arithmetic operators.
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
What is the output of the following code snippet?
int a = 10;
int b = 20;
int max = (a > b ) ? a : b ;
System.out.println(max);
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
What is the output of the following code snippet?
int a = 10;
a +=20;
System.out.println(a);
1 year ago |[YT] | 0
View 0 replies
Tech-Bimba (ಬಿಂಬ)
What is the output of the following code snippet?
int a = 10;
System.out.println(--a);
1 year ago |[YT] | 0
View 0 replies
Load more