Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


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



Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
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
The new keyword in java
The new keyword in java In this section you will learn about new keyword in java. The new keyword is used to create a instance of a class. The new keyword...; A ob1 = new A(12,56); Shape ob2 = new Shape(ob,32,98); First line creates
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
new
new    hi i am jane pls explain the difference between string greeting = good morning string greeting = new string ("good morning
new
new  hi the difference between string sname = good morning string sname =new("good morning
new
new    hi i am jane pls explain the difference between heap memory and stack memory
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
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
new
new   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html
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
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
Create new file in java
Create new file in java We are going to discuss how to create new file in java... in java File class representing the files and folder pathnames by location. With File class we create files and directories. Java File represents actual
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
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 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
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 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
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
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
What are New Features in JAVA SE 6
Here are the new features of the version 6 of the Java Standard Edition (SE... web services. The latest Java SE 6 provides new adds parsing and XML to Java.... Collections Framework Enhancement: With the new Java SE features, now
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
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
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 can add new line character into ajax response for java
how can add new line character into ajax response for java   i want... down will be in a new line how can i do this i m showing my codes here please... { xmlHttp=new XMLHttpRequest
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want... down will be in a new line how can i do this i m showing my codes here please... { xmlHttp=new
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
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I...) throws IOException { Test test = new Test(); test.execute...; TreeMap> xtsmMap = new TreeMap>(); try
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I...(String[] args) throws IOException { Test test = new Test...; TreeMap> xtsmMap = new TreeMap>(); try
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
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
New to struts2.0
New to struts2.0  hi am new to struts2.0 in my application i have declared a list in static how to get the static list values in my result.jsp??? if i remove the static in the list the result is getting displayed.why
New to struts2
New to struts2   Please let me know the link where to start for struts 2 beginners   Struts 2 Tutorials
new 2
new 2  <%@page import="java.util.ArrayList"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <...; arr1=new ArrayList<String>(); ArrayList<String> arr2=new
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
Java - Opening a url in new window from an applet
Java - Opening a url in new window from an applet  ... an applet. This program shows that how a url is opened in a new document or browser. When you click the button "google", new browser window will open
I am new to java applets. When i run this code on applet viewer status is displayed that applet not initialized
I am new to java applets. When i run this code on applet viewer status... void init() { lname =new Label("Username:"); lpwd=new Label("Password:"); tname=new TextField(20); tpwd=new TextField(20
loop gymnastics,new for in loop gymnastics,result set Iterable,java newsletter,tutorial
New for/in loop gymnastics 2005-02-07 The Java Specialists' Newsletter [Issue...] And now, let us get our teeth into the new for/in construct of Java... to you, we offer an excellent Java 5 delta course, that covers the new
Java - Opening a url in new window from an applet
Java - Opening a url in new window from an applet  ... how to open a new window from an applet. You can use the code given... will open new browser window and then show you the web page. Opening a new
How to add new class in Pkg using the feature of existing class - Java Beginners
How to add new class in Pkg using the feature of existing class   Hi Friends, I want to know , is it possible to add new class in a user Defined Package , which already contain any Class Having Public , Default, Protected
 

 

 

DMCA.com