Related Post

Spread the word

Digg this post

Bookmark to delicious

Stumble the post

Add to your technorati favourite

Subscribes to this post

2 Comments Already

mygif
William R Said,
September 4th, 2010 @8:04 am  

I know the feeling, I am taking an online computer science college course in high school right now, but to answer your question.

you need to make a keyboard or scanner class such as an io.

next you need to make the input an integer or a int.

next you would make another int. such as int square

so your program would look like:

import java.io.*;
import java.util.*;
public class Tester
{
public static void main(String args[])
{

System.out.print(”Please Enter a Number”);
Scanner keyboard=new Scanner(System.in);
int number=keyboard.nextInt();
int squared=number*number;
System.out.print(”your number squared is”);
System.out.print(” “);
System.out.print(squared);

}

}

mygif
jimmyjoeart Said,
September 4th, 2010 @8:11 am  

The high school kid thinks Java and JavaScript are the same. Here’s how you really do it:

//Write a JavaScript program that:
//reads a number from the keyboard…
var input = prompt( “Enter a number”, “” );
var num = parseFloat( input );
if (isNaN( num )) {
  alert( “Sorry, ‘” + input + “‘ is not a number.” );
} else {
  //squares it…
  num = Math.pow( num, 2 );
  //and prints the result…
  alert( input + ” squared = ” + num );
}