Answer in JAVA
1.
Complete the method definition to output the hours given minutes. Output for sample program:
3.5
import java.util.Scanner;
public class HourToMinConv {
public static void outputMinutesAsHours(double
origMinutes) {
/* Your solution goes here */
}
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
double minutes;
minutes = scnr.nextDouble();
outputMinutesAsHours(minutes); //
Will be run with 210.0, 3600.0, and 0.0.
System.out.println("");
}
}
2.
Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand. End with a newline. Ex: printFeetInchShort(5, 8) prints:
5' 8"
Hint: Use \" to print a double quote.
import java.util.Scanner;
public class HeightPrinter {
/* Your solution goes here */
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
int userFeet;
int userInches;
userFeet = scnr.nextInt();
userInches = scnr.nextInt();
printFeetInchShort(userFeet,
userInches); // Will be run with (5, 8), then (4, 11)
}
}
3.
Write a method printShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, print "Too few.". If more than 4, print "Too many.". Else, print "N: Lather and rinse." numCycles times, where N is the cycle number, followed by "Done.". End with a newline. Example output with input 2:
1: Lather and rinse. 2: Lather and rinse. Done.
Hint: Declare and use a loop variable.
import java.util.Scanner;
public class ShampooMethod {
/* Your solution goes here */
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
int userCycles;
userCycles =
scnr.nextInt();
printShampooInstructions(userCycles);
}
}
import java.util.Scanner; public class HourToMinConv { public static void outputMinutesAsHours(double origMinutes) { System.out.print(origMinutes / 60); } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); double minutes; minutes = scnr.nextDouble(); outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0. System.out.println(""); } }
import java.util.Scanner; public class HeightPrinter { public static void printFeetInchShort(int numFeet, int numInches) { System.out.println(numFeet + "' " + numInches + "\""); } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int userFeet; int userInches; userFeet = scnr.nextInt(); userInches = scnr.nextInt(); printFeetInchShort(userFeet, userInches); // Will be run with (5, 8), then (4, 11) } }
import java.util.Scanner; public class ShampooMethod { static void printShampooInstructions(int numCycles) { if (numCycles < 1) { System.out.println("Too few.."); } else if (numCycles > 4) { System.out.println("Too many.."); } else { for (int i = 1; i <= numCycles; ++i) { System.out.println(i + ": Lather and rinse."); } System.out.println("Done."); } } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int userCycles; userCycles = scnr.nextInt(); printShampooInstructions(userCycles); } }
Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for...
CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign is Teenager with false. 1 import java.util.Scanner; 3 public class TeenagerDetector 1 public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; D}]oll kidage = scnr.nextInt(); /* Your solution goes here */ Go USB if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 20 Run Feedback? CHALLENGE ACTIVITY 3.11.2: Boolean in branching statements. Write...
In JAVA ACTIVITY 3.10.1: Rock-paper-scissors. Write a switch statement that checks nextChoice. If o print "Rock". If 1 print "Paper". If 2 print "Scissors'. For any other value, print "Unknown'. End with newline. 2. 4 1 import java.util.Scanner; 3 public class Roshambo public static void main(String [] args) { 5 Scanner scnr - new Scanner(System.in); 6 int nextChoice; 7 8 nextChoice - scnr.nextInt(); 9 10 /" Your solution goes here */ 11 12 13} CHALLENGE ACTIVITY 3.10.2: Switch statement to...
(Java Zybooks) Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C import java.util.Scanner; public class NestedLoops { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int...
Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }
(Java Zybooks) Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C import java.util.Scanner; public class NestedLoops { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int...
Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print: 90, 92, 94, 95 Your code's output should end with the last element, without a subsequent comma, space, or newline. import java.util.Scanner; public class PrintWithComma { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int NUM_VALS = 4; int[] hourlyTemp = new...
Write a statement that outputs variable numTickets. End with a newline. import java.util.Scanner; public class VariableOutput ( public static void main (String D args) int numTickets; Scanner scnr new Scanner(System.in) scnr.nextint0:I/ Program will be tested with values: 15, 40. numTickets / Your solution goes here/
CHALLENGE ACTIVITY 3.5.1: Detect specific values. Write an expression that prints "Special number if specialNum is-99, 0, or 44. 1 import java.util.Scanner; 3 public class Find SpecialValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int specialNum; specialNum - scnr.nextInt(); POSLOVOU if (/* Your solution goes here */) { System.out.println("Special number"); else { System.out.println("Not special number"); Run View your last submission
In Java; Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C import java.util.Scanner; public class NestedLoops { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int...
CHALLENGE ACTIVITY 7.16.1: Enter the output of the ArrayList ADT functions. Jump to level 1 Type the program's output import java.util.ArrayList; import java.util.Scanner; public class IntegerManager ( public static void printSize(ArrayList<Integer> numsList) System.out.println(numsList.size() + "items"); public static void main(String[] args) Scanner scnr = new Scanner(System.in); int currval; ArrayList<Integer> intList = new ArrayList<Integer>(); Input 123-1 printSize (intList); Output currval = scnr.nextInt(); while (currval >= 0) { intList.add(currval); currval = scnr.nextInt(); printSize (intList); intList.clear(); printSize (intList); 1 2 Check Next