NEW IN JAVA

NEW IN JAVA

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
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
Advertisements
new java technologies 2012
new java technologies 2012  new java technologies 2012
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
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
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
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
new
new   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html
New to Java?
New to Java?       If you are new to Java technology and you want to learn Java and make...: New to Java? Understanding the Java Technology Java technology
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
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
How to make a new List in Java
How to make a new List in Java  Hi, I have to create list object in Java. How to make a new List in Java? Thanks (adsbygoogle... the new operator as shown below: List list = new ArrayList(); Thanks
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
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 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 to Java programming
New to Java Programming? How to learn and master Java programming language in less time? I am new to Java, how I can learn Java programming Language? Java... , Mobile Application. So, first thing in learning the Java programming language
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
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... FileNewDirectory { public static void main(String args[]) { File file = new File
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 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
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
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 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... { public static void main(String[] args) throws Exception { File f = new File("C
The new keyword
The new keyword       The new keyword in java programming language is used to create a new instance... a simple java object (non array object) by using the new operator. String
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
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
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 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...(String[] args) throws IOException { Test test = new Test...; 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...) throws IOException { Test test = new Test(); test.execute...; TreeMap> xtsmMap = new TreeMap>(); try
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
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
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:ADS_TO_REPLACE_1 Core
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 store String, characters, numbers etc. In Java to create a File for storing
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
Hibernate 6 New Features
_TO_REPLACE_1 Here are the new features of Hibernate 6.0: Java Persistence API... opportunity for future development with the help of new features of Java...Hibernate 6 New Features - What's new in the Hibernate 6 ORM? Hibernate 6
Hibernate 6 New Features
. Here are the new features of Hibernate 6.0: Java Persistence API is replaced... with the help of new features of Java. Related Tutorials Hibernate 6.0...Hibernate 6 New Features - What's new in the Hibernate 6 ORM? Hibernate 6
Maven dependency for com.eed3si9n - sjson-new-spray_2.12 version 0.13.0 is released. Learn to use sjson-new-spray_2.12 version 0.13.0 in Maven based Java projects
to use  com.eed3si9n - sjson-new-spray_2.12 version 0.13.0 in Java projects... a Maven project First of all you have to create a new Java project based on maven... that downloads and includes  com.eed3si9n - sjson-new-spray_2.12 version 0.13.0 java

Ads