Question
Problem #1: Write a program in Java to ask a user for input of a number. Check whether a number is even or odd and
Problem #1: Write a program in Java to ask a user for input of a number. Check whether a number is even or odd and display a message to that effect. Keep asking for input from the user until the user enters a code that designates to QUIT.
Here is what I have so far:
import java.util.Scanner;
public class OddEven {
public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Enter a number: "); int num = reader.nextInt(); if (num % 2 == 0) System.out.println(num + " is even"); else System.out.println(num + " is odd"); System.out.print ("Enter another number or enter quit to stop: ");
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started