In: Computer Science
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).
Create a java program which prints out a random goodwill message i.e. (Have a great day!) please have at least 4 messages.
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.
Write a JAVA program that calls a method that finds the smaller of two numbers input.
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.