I just started a programming class and stuck in a section of my assigment. i would like to know if someone could guide me to the right direction.

Last instruction:

" Write a script that reads an integer and determines and output XHTML text that displays whether it it odd or even.{hint: use the remainder operator. An even numder is a muiple of 2.
Any multiple of 2 leaves a remainder of zero when divided by 2.}

I would apreciate this a lot.


You need to use if/else with the remainder operator.

//Purpose: Check if number is odd or even.
import java.util.Scanner;
public class oddeven {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner (System.in);
		int x;
		System.out.print("Enter a number:");
		x = input.nextInt();
		System.out.println(x+" is even.");
		else if(x%2==0)
		System.out.println(x+" is even.");
		else if(x%2!=0)
		System.out.println(x+" is odd.");

Edited 7 Years Ago by shroomiin: n/a

hello shroomin

wow, thank you
I was wondering thought, this is for a really basic class,
This kinda of lot more advance then book showed us

does this code work in a html page
we also was told to use a (window.prompt )

haha well let me tell you somthing man, thats about as basic as its going to get. I too am in a intro to programming class, and that problem was on one of my assignments a few days ago. and were only on chapter 1 :(

but i feel your pain. i too am struggling. but im glad i was able to help you out.

edit- i have no idea if it works in a html page, we use a Java environment program called eclipse, which is a very common free program for java development.

Edited 7 Years Ago by shroomiin: n/a

This article has been dead for over six months. Start a new discussion instead.