Naseem
NEW IN JAVA
1 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners

View Answers

October 20, 2009 at 5:24 PM


Hi Friend,

Try the following code:

import java.util.*;

public class Operations {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
Random random1 = new Random();
Random random2 = new Random();
int menu = 0;
System.out.println("Test");
System.out.println();
System.out.println("1. Add");
System.out.println("2. Subtract");
System.out.println("3. Multiply");
System.out.println("4. Divide");
System.out.println("5. Exit");

boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();

switch(menu) {
case 1:
int r1=0,w1=0;
for (int idx = 1; idx <= 10; ++idx){
int ran1 = random1.nextInt(50);
int ran2 = random2.nextInt(50);
System.out.print(ran1 + " + " +ran2+" = ");
int add=scan.nextInt();
int total=ran1+ran2;
if(add!=total){
w1++;
}
else{
r1++;
}
}
System.out.println("Right="+r1);
System.out.println("Wrong="+w1);
if(r1>7){
System.out.println("Congratulations!");
}
else{
System.out.println("Please ask your teacher for help");
}
break;
case 2:
int r2=0,w2=0;
for (int idx = 1; idx <= 10; ++idx){
int ran1 = random1.nextInt(50);
int ran2 = random2.nextInt(50);
System.out.print(ran1 + " - " +ran2+" = ");
int sub=scan.nextInt();
int total=ran1-ran2;
if(sub!=total){
w2++;
}
else{
r2++;
}
}
System.out.println("Right="+r2);
System.out.println("Wrong="+w2);
if(r2>7){
System.out.println("Congratulations!");
}
else{
System.out.println("Please ask your teacher for help");
}
break;
case 3:
int r3=0,w3=0;
for (int idx = 1; idx <= 10; ++idx){
int ran1 = random1.nextInt(50);
int ran2 = random2.nextInt(50);
System.out.print(ran1 + " * " +ran2+" = ");
int mul=scan.nextInt();
int total=ran1*ran2;
if(mul!=total){
w3++;
}
else{
r3++;
}
}
System.out.println("Right="+r3);
System.out.println("Wrong="+w3);
if(r3>7){
System.out.println("Congratulations!");
}
else{
System.out.println("Please ask your teacher for help");
}
break;
case 4:
int r4=0,w4=0;
for (int idx = 1; idx <= 10; ++idx){
int ran1 = random1.nextInt(50);
int ran2 = random2.nextInt(50);
System.out.print(ran1 + " / " +ran2+" = ");
int div=scan.nextInt();
int total=ran1/ran2;
if(div!=total){
w4++;
}
else{
r4++;
}
}
System.out.println("Right="+r4);
System.out.println("Wrong="+w4);
if(r4>7){
System.out.println("Congratulations!");
}
else{
System.out.println("Please ask your teacher for help");
}
break;
case 5:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}

Thanks









Related Pages:
New to Java - New to java tutorial
Technical description of Java Mail API       This section introduces you with the core concepts of Java Mail API. You must understand the Java Mail API before actually delving
New To JAVA - Java Beginners
New To JAVA  hi iam new to java..,can you please guide me how to learn the java and also tell me how many days it takes to learn java  Hi... will get more information about java. Read more detail. http
new java technologies 2012
new java technologies 2012  new java technologies 2012
add new package java
add new package java  How to add new package in Java
new java technologies 2011
new java technologies 2011  what are the new java technologies in 2011
NEW IN JAVA - Java Beginners
NEW IN JAVA  Suppose you are asked to design a software tool... static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); Random random1 = new Random(); Random random2 = new Random(); int
opening new browser with new JSESSIONID using java
opening new browser with new JSESSIONID using java  I am facing following problem, I am trying to open a new browser using java. First i have opened one IE browser and manually. And i ran my LaunchURL.java file, it is opening new
New to Java Please help
New to Java Please help  Hi I need help, can some one help me.... Thanks!   If you are new in java, then you need to learn core java concepts.So go through the following link: Core Java Tutorials Here, you will find
Very new to Java
Very new to Java   hi I am pretty new to java and am wanting to create a programe for the rhyme 10 green bottles. 10 green bottles standing on the wall 10 green bottles standing on the wall and if 1 green bottle should
New to Java?
New to Java?       If you are new to Java technology and you want to learn Java and make career in the Java technology then this page is for you. Here we have explained how to learn
The new keyword
The new keyword       The new keyword in java programming language is used to create a new instance... an instance of a class or an array by using the new operator. Creating a simple java
im new to java - Java Beginners
im new to java  what is the significance of public static void main... for a java class to execute it as a command line application. public- It provide...- It specifies the return type. main- This method in java is designed
New to programming...
New to programming...... Break the old rhythm. Explore the new horizons.  Be a crew member to  the new Ship... After decades of R & D's
new String(text) - Java Beginners
(text): In this Case Java will create a new String object in normal (non-pool...new String(text)  Please, what is the difference between this.text = text; and this.text = new String(text); in the example: public
Java create new array of strings.
Java create new array of strings.  Java create new array of strings.   Example: public class StringArray { public static void main... (eg. int,char,float etc). For example String name[]=new String[7
opening new window - Java Beginners
opening new window  Hi All, I have two classes with me , lets say A and B.when I press a button in class A , the class B should open in a new window.i.e., I want to know, how a new window(B) can be opened by clicking a button
new
new    hi i am jane pls explain the difference between string greeting = good morning string greeting = new string ("good morning
new
new    hi i am jane pls explain the difference between heap memory and stack memory
new
new  hi the difference between string sname = good morning string sname =new("good morning
What's New?
What's New? Find latest tutorials and examples at roseindia.net. Our site is publishing free tutorials on many Java and Open source technologies Learn Java technologies step by step: Core Java JSP
Java new arraylist
Java ArrayList object is created with the reference of List interface Object is also created directly by the ArrayList class Java New Arraylist..."}; //ArrayList list=new ArrayList(); List list=new ArrayList(); list.add(ar[0
Java file new directory
Java file new directory In this section, you will learn how to create a new directory. Description of code: This is a common task. The java.io.package... { public static void main(String args[]) { File file = new File("Hello
new
new   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType="text/html" pageEncoding="UTF-8"%> Location Fill Up Your Details <center> <form action="hit" method="POST">
New Features of JAVA SE 6.
New Features of JAVA SE 6.   .... Changes in I/O This is a new feature added in Java SE 6, which has... in JAVA SE 6 and JPDA has been added. Some new Methods are included like boolean
New Page 1
JavaScript loop through In this Tutorial we want to describe you a code that help you in understanding JavaScript loop through. We are using Java Script language as scripting language. The for loop execute and run the script till
Java file new line
Java file new line In this section, you will learn how to write the text in new line of text file. Description of code: The package java.io.* has provide... main(String[] args) throws Exception { File f = new File("C:/file.txt
How To Create a New File
How To Create a New File In this section we will discuss about how to create a new file in Java. A Computer File is a storage of data. In this file we can... which will demonstrate you about how to create a new file in Java
JSP 2.0 - New Features
;    JSP 2.0  is released with new promises. JSP 2.0 is an upgrade to JSP 1.2 with several new and interesting features... with the objective of making the life of Developers easy. Here is the new features of JSP 2.0
Java file create new file
Java file create new file This section demonstrates you how to create a new.... Java makes this easy by providing many useful tools. Through the use of these tools, you can can easily create a new empty file. Now for this task, we have
How to create new arraylist using Java
someone provides online example how to create new arraylist in java programming. thnaks,   Hi, In java programming language you can create new...How to create new arraylist using Java  hi, I want to develop
adding some value to new column
adding some value to new column   how to update a column having some value into new column that also have some value i need to add this two value in java using result set we can get all the column data but how to add these value
New Features in JDBC 4.0
New Features in JDBC 4.0       Introduction Java database connectivity (JDBC) is the Java Soft specification... and classes written in the Java programming language. The applications can be written
Inserting a New Entry in a List
Inserting a New Entry in a List       This Example shows you how to Insert a new Entry in a list  in a DOM document. JAXP (Java API for XML Processing) is an interface which
What's new in JDBC 3.0?
What's new in JDBC 3.0? In this section we will learn about the new features of JDBC 3.0. The new version of JDBC 3.0 is released with many new features and a number of new functionalities. This section explains the news
How to allocate a new int buffer in java.
How to allocate a new int buffer in java.  In this tutorial, we will see how to allocate a new int buffer. IntBuffer API: The java.nio.IntBuffer...;} } Output C:\>java AllocateIntBuffer Position of IntBuffer :0
How to allocate a new long buffer in java.
How to allocate a new long buffer in java.  In this tutorial, we will see how to allocate a new long buffer. LongBuffer API: The java.nio.LongBuffer...;} } Output C:\>java AllocatLongBuf Capacity
Write Text To File In New Line.
Write Text To File In New Line. In this tutorial you will learn how to write text into file in a new line. When you are writing in a file you may be required to finish the line and want to write the other text in a new line
How to create a new text file that contains the file names of the copied files in a new directory? - Java Beginners
How to create a new text file that contains the file names of the copied files in a new directory?  Okay so my question is: How to create a new text file that contains the file names of the copied files in a new directory
How to run program in new opened cmd
How to run program in new opened cmd  Hello i have made a program in java to open command prompt, then how to run my left of the program in the new opened command prompt
New Releases
New Releases           Sun?s released the Java Wireless Toolkit 2.5.2 Sun has released the Java Wireless Toolkit 2.5.2. The Toolkit includes build tools, utilities
How to write file text In New Line
How to write file text In New Line  Hi friends, How to write file text in new line in Java program. How to write the syntax for this with example... to write file text in New line in Java
New Releases
New Releases        ... Interface21 has announced the release of Spring Web Services 1.0. With this new release, Java programmers can develop applications for Web services
Java append new node to XML file
Java append new node to XML file In this tutorial, you will learn how to append new node to xml file. Sometimes there is a need to append a new XML node to the xml file. Here is an xml file where we are going to append a new node
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW - Java Beginners
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW   PLS TELL ME? HOW CAN I DEFINE A WINDOW.OPEN FUNCTION WITHIN ANOTHER FUNCTION e.g... DATA, IT MUST OPEN A WEB SITE IN A NEW WINDOW. SPECIFICATION:MAKING ONLY "1
New Releases
New Releases        ... released. RSF is an open source Java web framework that is built on spring framework. There are number of existing Java frameworks managing the stateful components
New Features of Spring Framework 3.2
now supports new improved features of Java SE 7...Spring Framework 3.2 released is with many new features and enhancements. Its final version of the of the Spring Framework 3.2. It recommended that the users
How to Create New Excel Sheet Using JSP
a new  excel sheet using java .You can create any number of  new excel... How to create new excel sheet using jsp  ... Jakarta(Jakarta POI - Java API To Access Microsoft Format Files ) Tomcat. You can
How do I do this program? I'm new to Java programming...
How do I do this program? I'm new to Java programming...  Suppose you want to print out numbers in brackets, formatted as follows: [1] [2] [3] and so on. Write a method that takes two parameters: howMany and lineLength
Need to decide technologies to create new social site web application in java
Need to decide technologies to create new social site web application in java  Hi, I want to create a social site in java, j2ee which should support thousands of user. I want to keep it very simple and light. So few of my
How to insert new line after every space in java
How to insert new line after every space in java  Hii Sir, I have a string with values 69 17 17 16 2 1 1 26 26 56 like this .Now as per my need i have to put all these values into new lines on getting space

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.