Share on Google+Share on Google+

langat
math radom
1 Answer(s)      9 years ago
Posted in : Java Beginners

Computers are playing an increasing role in education. Write a program that will help an elementary school student learn multiplication. Use Math.random to produce two positive one-digit integers. The program should

Ads

View Answers

April 11, 2008 at 7:10 PM


Hi friend,

import java.util.*;
import java.util.Scanner;

public class MultiplicationRandom{
public static void main(String[] args){
int num1 = 0;
int num2 = 0;
int num;
int user;
num1 = (int)(Math.random() * 9+1);
num2 = (int)(Math.random() * 9+1);
num = num1 * num2;
while(true){
// get answer from user
Scanner input = new Scanner(System.in);
System.out.println("How much is " + num1 + " TIMES " + num2 + "?");
user = input.nextInt();
if(user!= num){
System.out.println( "No. Please try again.");
}
else{
System.out.printf( "Very Good!");
}
}
}
}










Related Tutorials/Questions & Answers:
java Math class
java Math class  Why are the methods of the Math class static
Java math class
Java math class  Can you instantiate the Math class
Advertisements
Java math class
Java math class  Why can?t I say just abs() or sin() instead of Math.abs() and Math.sin
Math Constants and Functions using JavaScript
Math Constants and Functions using JavaScript  What's Math Constants and Functions using JavaScript
Math Program - Java Beginners
Math Program  The greatest common divisor of two integers 16 and 24 is 8. Develop the algorithm for finding the greatest common divisor of two numbers. Write a program that prompts the user to enter two integers and calculates
Evaluating a math expression given in string form
Evaluating a math expression given in string form  Evaluating a math expression given in string form
which part of the cpu does math calculations
which part of the cpu does math calculations  which part of the cpu does math calculations logical calculation
Can you instantiate the Math class? - Java Beginners
Can you instantiate the Math class?   Hi, Can you create object of Math class? Thanks   Hi, All the methods in Math class is static. The constructor is not public in the Math class. So, we can't create
Java - Math class in Java
Java - Math class in Java       In this example you will learn about Math class. This example explains how you can use functions provided by the Math class like E, PI, round, abs
Introduction To Math Class In Java
Introduction To Math Class In Java In this tutorial we will read about.... Math class is created inside the java.lang package and the classes created inside... the application. Class Declaration public final class Math extends Object Constant
Mysql Math Function
Mysql Math Function       Math Function involved in Mysql when we perform some operation... 'Mysql Math Function'. The below Syntax help you to perform Math Function : ABS(X
Mysql Math Function
Mysql Math Function       Math Function involved in Mysql when we perform some operation... an example from 'Mysql Math Function'.The below Syntax help you to perform Math
JavaScript exp method
by using the Math object reference. In Math object we have some very useful.... The exp() method of Math object returns the value of ex , where "e"
TeXlipse
closing of acrobat on Windows, smartkeys, reference hovers and math commands... also. Some of the new things: more command completions, more math modes, syntax
XML Interviews Question page9
, if the document type you use provides for math, and your users' browsers... other DTDs, such as ISO 12083 Math, or OpenMath, or one of your own making. Browsers which display math embedded in SGML existed for many years (eg DynaText
Randomizer
by using the random() method of the Math class and change them into different... by the randomFloat() method by using the round() method of the Math class. Now we
Give difference between LinkedList and ArrayList - Java Beginners
, Differences: ArrayList provides fast radom access while LinkedList does
Change a file timestamp
C:\vinod\Math_package>javac ChangeFileDate.java C:\vinod\Math_package>java ChangeFileDate Change file timestamp example! Enter file name with extension: StrStartWith.shtml Enter last
Intro Java help with Double
Intro Java help with Double  I have to evaluate a math expression using double in Java. I can input the code fine for the expression, but I don't know how to view the answer that it gives me. help
Question in Java ??
Question in Java ??   Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number squrfoot
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
java - Java Beginners
java  i have to make a programm in java to multiply any number with 100 without using any math operator.  To multiply with 100 no need of mathematical operators. int result=Integer.parseInt(String.valueOf(num)+"00
PHP list array
,'jack', 'math');      list($roll, $name, $subject... is math
Random in jsp
. random() is a method of Math class which extends java.lang package. The Math... we are going to make a use of random() method of the Math class. We are using
For Loop/PHP
For Loop/PHP  Write a class called math. It is to have one property called num. It also has one method called factorial. This method is to start...;Here is a java example that finds the factorial of a number. public class math
Apollo for Eclipse
++ templates for parallelism, math processing, and multimedia libraries...) and Intel® Math Kernel Library (Intel® MKL). While these libraries
C++ Compiler for Linux
++ templates for parallelism, math processing, and multimedia libraries...) and Intel® Math Kernel Library (Intel® MKL). While these libraries are available
java program
of a circle and calculate area? formula=pirr (use math class) sample output
Lang and Util Base Libraries
, a basic math class etc. It also provide wrapper class. Math Math functionality includes floating point libraries and arbitrary-precision math. Monitoring
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads