Question

In: Computer Science

Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do...

  1. Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do we appreciate!" (hint use a for loop).

  2. Create a java program which prints out a random goodwill message i.e. (Have a great day!) please have at least 4 messages.

  3. Write a java program that will ask the user to enter a number and print out to the screen until the number -3 is entered.

  4. Write a JAVA program that calls a method that finds the smaller of two numbers input.

Solutions

Expert Solution

Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do we appreciate!" (hint use a for loop).

class Main {
public static void main(String[] args) {
  
for (int i = 2; i <= 8; i=i+2)
System.out.println(i);

System.out.println("Who do we appreciate!");
}
}

Create a java program which prints out a random goodwill message i.e. (Have a great day!) please have at least 4 messages.

import java.util.*;
class Main {

  
public static void main(String[] args)
{
Random t = new Random();
System.out.println(goodwill_message(t.nextInt(100)%4+1));
}

public static String goodwill_message(int n) {
String message = "";
switch (n) {
case 1: message = "Have a great day!"; break;
case 2: message = "Good Morning"; break;
case 3: message = "Good Boy"; break;
case 4: message = "Good Evening"; break;
default:message = "Good Night";
}
return message;
}
}

Write a java program that will ask the user to enter a number and print out to the screen until the number -3 is entered.


import java.util.Scanner;
class Main {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = 1;
System.out.println("Enter number ");
while(n!=-3)
{
n = in.nextInt();
System.out.println(n);
}
}
}

Write a JAVA program that calls a method that finds the smaller of two numbers input.

import java.util.Scanner;
public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = minFunction(a, b);
System.out.println("Smaller Number = " + c);
}

/** returns the minimum of two numbers */
public static int minFunction(int n1, int n2) {
int min;
if (n1 > n2)
min = n2;
else
min = n1;

return min;
}
}

please give a upvote if u feel helpful.


Related Solutions

python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
Write a Java program that takes in a string and a number and prints back the...
Write a Java program that takes in a string and a number and prints back the string from the number repeatedly until the first character... for example Pasadena and 4 will print PasaPasPaP. Ask the user for the string and a number Print back the string from the number repeatedly until the first character For both programs please utilize: methods arrays loops Turn in screenshots
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
1.Write a Java program that prompts the user for a month and day and then prints...
1.Write a Java program that prompts the user for a month and day and then prints the season determined by the following rules. If an invalid value of month (<1 or >12) or invalid day is input, the program should display an error message and stop. Notice that whether the day is invalid depends on the month! You may assume that the user will never enter anything other than integers (no random strings or floats will be tested.) Tips: Break...
JAVA PROGRAMMING Write a program that ask the user for a number then prints the cube...
JAVA PROGRAMMING Write a program that ask the user for a number then prints the cube of the number. The program should be called CubeNumbers. Use a value returning method with parameter, call the method myCube.
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a function which takes one parameter int num, and prints out a countdown timer with...
Write a function which takes one parameter int num, and prints out a countdown timer with minutes and seconds separated by a colon (:). It should print out one line for each second elapsed and then pause one second before printing out the next line. A few things to note: - You can assume that calling the function usleep(1000000) makes the program pause for one second - It should count down from num minutes:zero seconds to zero minutes:zero seconds -...
Use if statements to write a Java program that inputs a single letter and prints out...
Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way: 2 = ABC    3 = DEF   4 = GHI    5 = JKL 6 = MNO   7 = PRS   8 = TUV 9 = WXY No digit corresponds to either Q or Z. For these 2 letters your program should print a message indicating that they are not...
in .java Write a program that reads an integer with 3 digits and prints each digit...
in .java Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ... Enter an integer of exactly 3 digits(e.g. 538): 319 9 1 3 Hint: consider what you get from these operations: 319%10 319/10 31%10
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT