Which of the following statements uses a Scanner variable named sc to return the next value the user enters at the consolse as a String object and store it in a variable named city?
a. |
String city = sc.next(); |
|
b. |
String city = sc.nextString(); |
|
c. |
String city = sc.next().toString(); |
|
d. |
String city = sc.nextValue(); |
Which of the following statements uses a Scanner variable named sc to return the next value...
public static void main(String[] args) { System.out.println("Welcome to the Future Value Calculator\n"); Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDoubleWithinRange(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 30); int years = getIntWithinRange(sc, "Enter number of years: ", 0, 100); System.out.println(); ...
Consider the following code snippet. Scanner inputFile = new Scanner("hoursWorked.txt"); Which of the following statements is correct? This code will open an existing file named "hoursWorked.txt" for reading. This code will create a new file named "hoursWorked.txt". This code will treat the string "hoursworked.tht" as an input value. This code will open a file named "hoursworked.txt" for writing. • Previous
Will upvote C++ 1. (7 points) Define a class named “IntegerVariable” that manages a variable name (string) and an integer value. The data members must be declared as "private." The class must provide at least the following methods: a. "isSame VariableName" that compares with another Integer Variable object. It returns true if they both have the same variable name, and false otherwise. b. "toString" method to return string representing the variable information (name and value) c. "getValue” to return its...
JAVA Codelab (20940): [Sequential and Nested if/else Statements] Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessary code to read a value into into response and then carry out the following: if the value typed in is a 1 or a 2 then increment yesCount and print out "YES WAS RECORDED" if the value typed in is a 3 or an 4 then increment noCount and print out...
1) Which of the following is the name of a local variable in the Strange class below? public class Strange{ public static final int MAX = 5; public static void unknown(){ int number = 0; for (int i = MAX; i >= 1; i--) number += i * i; System.out.println(number); } public static void main(String[] a){ unknown(); } } a) Strange b) int c) MAX d) number e) main 2) Which of the following is NOT a method of the...
Which of the following statements prints a variable named total to the console, followed by a new line character? a. System.out.print(total); b. System.out.println(total); c. Console.out.println(total); d. Console.out.print(total);
Which of the following IF-THEN statements will not assign a value of 1 to the variable named Flag for patients with an eye color of blue or brown? IF EyeColor = 'blue' OR 'brown' THEN Flag = 1; b. IF EyeColor = 'blue' OR EyeColor = 'brown' THEN Flag = 1; c. IF EyeColor IN ('blue','brown') THEN Flag = 1; d. All of the above will work
QUESTION 1 Given two double variables named x and y, which of the following statements could you use to initialize both variables to a value of 0.0? a. x | y = 0.0; b. x = y = 0.0; c. x, y = 0.0; d. none of the above 1 points QUESTION 2 When you use a range-based for loop with a vector, you a. can avoid out of bounds access b. must still use a counter variable c....
This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...
1.which of the following are methods of the JDK iterator interface? a) hasNext() b) next() c) both a and b d) neither a nor b 2.what is the purpose of the static method named instance() in a singleton class a) to create the only instance of the singleton class (if needed) and return it b) To receive the only instance of the singleton class as a parameter and store it in the field of the class c) To query the...