Fill the code to get the value for the variables based on their data type. blank ;public class Main{ public static void main(String args[]) { Scanner sc= blank ; int a = blank ; float f = blank ; double salary= blank ; char gender= blank ; //String without space String firstName= blank ; //String with space String city= blank ; }}sc.nextFloat() new Scanner(System.in) sc.nextLine() sc.nextDouble() sc.nextInt() import java.util.Scanner sc.next() sc.next().charAt(0)
Question
Fill the code to get the value for the variables based on their data type. blank ;public class Main{ public static void main(String args[]) { Scanner sc= blank ; int a = blank ; float f = blank ; double salary= blank ; char gender= blank ; //String without space String firstName= blank ; //String with space String city= blank ; }}sc.nextFloat() new Scanner(System.in) sc.nextLine() sc.nextDouble() sc.nextInt() import java.util.Scanner sc.next() sc.next().charAt(0)
Solution
Here is the completed code:
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
float f = sc.nextFloat();
double salary = sc.nextDouble();
char gender = sc.next().charAt(0);
String firstName = sc.next();
String city = sc.nextLine();
}
}
Here is the explanation:
-
import java.util.Scanner;- This line is used to import the Scanner class which is used to get input from the user. -
Scanner sc = new Scanner(System.in);- This line is used to create an object of the Scanner class. -
int a = sc.nextInt();- This line is used to get integer input from the user. -
float f = sc.nextFloat();- This line is used to get float input from the user. -
double salary = sc.nextDouble();- This line is used to get double input from the user. -
char gender = sc.next().charAt(0);- This line is used to get the first character of the next string input from the user. -
String firstName = sc.next();- This line is used to get a string input from the user. Thenext()function only returns the next token/word in the input as a string. -
String city = sc.nextLine();- This line is used to get a string input from the user. ThenextLine()function returns the rest of the current line, including any spaces.
Similar Questions
Arrange the below code in correct order :import java.util.Scanner;public static void main(String args[]) {Scanner sc=new Scanner(System.in);public class Main{int num1 = sc.nextInt();System.out.println("The value is "+num1);}}
import java.io.*;import java.util.*;public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Myint = scanner.nextInt(); double d = scanner.nextDouble(); scanner.nextLine(); String mystring = scanner.nextLine(); System.out.println(mystring); System.out.println(d); System.out.println(Myint); /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ }}
String note = "14 23.0 \n\nhello\n cs200";Scanner input = new Scanner(note);System.out.println("$" + input.next() + "$"); System.out.println("$" + input.nextLine() + "$"); System.out.println("$" + input.nextLine() + "$");
Consider the following Java statements.Scanner input = new Scanner(System.in);float radius = input.nextFloat();double area;Which of the variables in this piece of code are reference variables?Group of answer choicesinputradius, inputarearadius, area.
Select the correct answerWhat will be the output of the following Java program?class java { public static void main(String args[]) { int var1 = 3; int var2 = 8; if ((var2 = 2) == var1) System.out.print(var2); else System.out.print(++var2); } }Options4213
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.