Java Question
Please highlight the 1 correct option from 4 given at bottom
What code would you use to tell if "schwifty" is of type String?
"schwifty".getClass().getSimpleName() == "String"
"schwifty".getType().equals("String")
"schwifty".getType() == String
"schwifty" instanceof String
in java To check a variable type we can use below:
variable instanceof variable_type
So to tell if "schwifty" is of type String?
ans) d) "schwifty" instanceof String
Java Question Please highlight the 1 correct option from 4 given at bottom What code would...
Java Question Please highlight the 1 correct option from 4 given at bottom What method signature will work with this code? boolean healthyOrNot = isHealthy(“avocado”); public void isHealthy(String avocado) boolean isHealthy(String string) public isHealthy("avocado") private String isHealthy(String food)
Java Question Please highlight the 1 correct option from 4 given at bottom Which code snippets are valid return statements for method1() and method2()? public void method1(){ // CODE SNIPPET 1 } public Float method2(){ // CODE SNIPPET 2 } return null; for CODE SNIPPET 1 and return 12.3; for CODE SNIPPET 2 return; for CODE SNIPPET 1 and return null; for CODE SNIPPET 2 return null; for both CODE SNIPPET 1 and CODE SNIPPET 2 return; for CODE SNIPPET...
Can you please translate this code from Java to C++;
These are the only libraries i am allowed to use
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
using namespace std;
1 /* Given a string, compute recursively (no loops) a new string where all * appearances of "pi" have been replaced by "3.14". public String changepi(String str) { if(str.length() <= 1) return str; if(str.substring(0, 2).equals("pi")) return "3.14" + changepi(str.substring(2)); 11 12 return str.charAt(0) + changepi(str.substring(1)); }
In java given the following code how would I validate that that upper case & lower case letters are are ignored and accepted as the same? // TODO add your handling code here: String name = nameTextField.getText().trim(); if(name.isEmpty()){ JOptionPane.showMessageDialog(this, "Username field is empty. Please correct."); return; } if(name.indexOf(" ")!=-1){ JOptionPane.showMessageDialog(this, "Username field cannot contains space in it. Please correct."); }
USING JAVA
Question 1 The following code would successfully loop through all of the characters in the String str given that the length of str is greater than 1. for(int i = 1; i < str.length(); i++) { //code not shown True False
Java 6. What is the output (what prints) given the following code? double xy = 1/2; System.out.println(xy); 7. How do you fix the code in #6 above? 8. What is the import statement? 9. Show an example of how to use one of the String methods. 10. What are escape characters? Give examples.
Bottom section is the what they expect in the code in java Create a class in JobApplicant.java that holds data about a job applicant. Include a name, a phone number, and four Boolean fields that represent whether the applicant is skilled in each of the following areas: word processing, spreadsheets, databases, and graphics. Include a constructor that accepts values for each of the fields. Also include a get method for each field. The get method should be the field name...
This question is about java program. Please show the output and the detail code and comment.And the output (the test mthod )must be all the true! Thank you! And the question is contain 7 parts: Question 1 Create a Shape class with the following UML specification: (All the UML "-" means private and "+" means public) +------------------------------------+ | Shape | +------------------------------------+ | - x: double | | - y: double | +------------------------------------+ | + Shape(double x, double y) | |...
20. wordList is type ListInterface<String>. What is printed? wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.replace(2, "train")); none of these is correct 2 false true car train you cannot tell from the provided code boat plane null Question 21 wordList is type ListInterface<String>. What is printed? wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.replace(4, "train")); train plane null none of these is correct car true false an exception will be thrown boat you cannot tell from the provided code 22. wordList is type ListInterface<String>. What is printed? wordList.add("sun");...
My Java code from last assignment:
Previous Java code:
public static
void main(String args[]) {
// While loop set-up
boolean flag = true;
while (flag) {
Scanner sc = new
Scanner(System.in);
// Ask user to enter employee number
System.out.print("Enter employee
number: ");
int employee_number = sc.nextInt();
// Ask user to enter last name
System.out.print("Enter employee last
name: ");
String last_name = sc.next();
// Ask user to enter number of hours worked
System.out.print("Enter number of
hours worked: ");
int hours_worked =...