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



Home Answers Viewqa Java-Beginners need help with java program as soon as possible

Have Programming Question? Ask it here!
 
 
 


Cathy Dinh
need help with java program as soon as possible
1 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


So my assignment is to write a program that used while loops to perform 6 different things. 1. prompt the users to input two integers: firstNum and secondNum (firstNum must be less than secondNum). 2. output all the odd numbers between firstNum and secondNum inclusive 3. output the sum of all the even numbers between firstNum and secondNum inclusive 4. output all the numbers and their squares between 1 and 10 5. output the sum of the squares of all the odd numbers between firstNum and secondNum inclusive 6. output all the uppercase letter. and lastly there is a hint: if currentNum % 2 = 0, then the currentNum is an even number. Otherwise it is an odd number.


Advertisement
View Answers

November 22, 2010 at 11:43 AM


Hi Friend,

Try the following code:

import java.util.*;
public class NumberExample{
    public static void main(String[]args){
        int sum=0,sumSquares=0;
        int num1=0,num2=0;
    Scanner input=new Scanner(System.in);
    System.out.print("Enter First Number: ");
     num1=input.nextInt();

    System.out.print("Enter Second Number: ");
     num2=input.nextInt();

    if(num1>num2){
    System.out.print("Your First Number is greater than second.So Please re-enter: ");
    num1=input.nextInt();
    }
    else{
        System.out.println("Odd Numbers: ");
while(num1 <= num2) {
if(num1%2 != 0) {
System.out.println(num1);
sumSquares+=(num1*num1);
}
if(num1%2 == 0) {
sum+=num1;
}
num1++;
}
System.out.println("Sum Of Even Numbers: "+sum);
System.out.println("Numbers and their squares between 1 and 10");
int i=1;
while(i <= 10) {
System.out.println(i+"    "+(i*i));
i++;
}
System.out.println("Sum Of square of odd Numbers: "+sumSquares);
}
    }
}

Thanks



Related Tutorials/Questions & Answers:
need help with java program as soon as possible
need help with java program as soon as possible  So my assignment is to write a program that used while loops to perform 6 different things. 1. prompt the users to input two integers: firstNum and secondNum (firstNum must be less
java program...need help as soon as possible!!! - Java Beginners
java program...need help as soon as possible!!!  Modify the Lexer (15.... 4. Print each token with line number READLINE: program { int i int j program left: 0 right: 6 line: 1 { left: 8 right: 8: line: 1 int
Advertisements
need help with a program - Java Beginners
Java algorithm - need help with a program  Java algorithm - need help with a program
need help with a program - Java Beginners
need help with a program   Part I An algorithm describes how... by the user. The output of the program should be the length and width (entered.... First you would need to make up the "test data". For this algorithm, the test data
need help on writing a program. - Java Beginners
Writing first Java Program  Hi, I need help to write my first Java Program other then Hello World! Thanks!!  Hi Thanks for choosing roseIndia to get your query solved. check given link to see the solution of your Java
need help creating a lift program - Java Beginners
need help creating a lift program  Classes, Methods, Constructors please i need help to create an elevator program Simulating an Elevator write an Elevator class containing various methods. Then, write a program
plz plz rply as soon as possible
plz plz rply as soon as possible  by using c programs * * * * * s s s s s * s s o s s s s s s s s s s s s s s s s s s s s s s s
need help with program
need help with program  To write a program to read a set of words from a file and return the following 1)Each word in the file against its frequency 2) the frequency should be in the descending order of the frequencies
need help with program
need help with program  To write a program where we can take two integer array as input,Find the missing number from array"B" has all the numbers from array"A" except one,and find the fastest way in doing
Need help with console program?
Need help with console program?  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). thanks in advance.   Here is an example that repeatedly
plz plz plz inform me as soon as possible
plz plz plz inform me as soon as possible  ``by using c programs how to type
hi see and give me reply as soon as possible
hi see and give me reply as soon as possible  Hi Friend, I got path,but it will again ask path error first i was gave index.jsp.It... be send reply soon. Thanks & Regards, N.Ramesh
Two compilation errors.Can anyone help soon. - Java Beginners
Two compilation errors.Can anyone help soon.  a program called.... The Date object should always remain in a consistent state. Write a program... year. My program:- package datejavaapp; /** * * @author TKS
Need help writing a console program
Need help writing a console program  I need help cant seems to figure it out! Write a program that consists of three classes. The first class will be the actual program. The second class will simply convert a string to lower
Need Help in Java programming
Need Help in Java programming  Hello. Can someone please help me with writing the following program Java program that gives assignment details such as:assignment number,assignment name,due date,submission date,percentage marks
really need help on how to write this program plz some 1 help out. - Java Beginners
really need help on how to write this program plz some 1 help out.  i am confused here on what to write can some 1 help out here i dont quite... a Java program that displays the following prompts: Enter
Need help on JAVA JSP
Need help on JAVA JSP  Hi, I have never worked on java and I have... using JAVA JSP). e.g. Tool does not adjust with the resolution of the screen(need to know how I can adjust it based on the cureen system's screen resolution
need help - Java Beginners
need help  Need help in programming in Java  Simple java program that will show the output within quotes using system.out.println... of this program is : " * "" *** "" ***** ""
Need help - Java Beginners
Need help   To Write a Java program that asks the users to enter a m..., respectively. The program stores this matrix into a two dimensional m*n array...; Hi Friend, Please try the following code. We hope that this code will help
Need Help - Java Beginners
Need Help  Hello Sir, Am a beginner of Java. Also i did course... projects in Java as well as J2EE... Can u help me and guide to do a project.../reference/tutorials/ http://netbeans.org/kb/trails/java-ee.html http
Need help in java programming
Need help in java programming  Hello. Can someone please help me with writig the following programm. Assignment 20% Presentation 10% Mini Test 10% Exam 60% Java program that accepts the following details: student
need help. - Java Beginners
program code and get to the output in uppercase letter.amar
beginner need help with online ordering program please
beginner need help with online ordering program please  I have created a program for an online ordering system and now have to add error handling and a few other things my teacher doesn't teach well is there a template I can go
need a java program for the following
need a java program for the following  Write a java program with three horizontal sliders. Name the sliders, the first one as red, the second one as green and the third one as blue. You design the program such that on varying
pls give me answer ae soon as possible - Ajax
pls give me answer ae soon as possible  i m writing code of ajax technology ...but it is not working pls check it n give me response quickly... give me quick response!!! thanks & regards shashank gupta
Need help in completing a complex program; Thanks a lot for your help
Need help in completing a complex program; Thanks a lot for your help  Hi, I am currently working on one program which works in this way. 1... content is user inputted and static content is prewritten. 3) We need to search
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
need program - Java Beginners
need program  I need a java program to get the multiple student name and mark.display the student information by sorting the marks in ascending or desending order.  Hi Friend, Try the following code: import
Need a java program
Need a java program  Write a code of java to print the fibonacci series.   for(int j=1;j<=5;j++) { int i,a,b,c; a=1;b=1;int n=5; System.out.print("fibonicci series is " + a +" " + b
Java Programming Need Help ASAP
Java Programming Need Help ASAP  You are required to develop..., maths mark, communications mark. You will then need accessor and mutator methods... class that creates an array of Students and handles it. You will need
Need *Help fixing this - Java Beginners
Need *Help fixing this  I need to make this program prompt user to login and then set program visibility to be true save volume output to file and maybe add retrieve function //need help with this one badly. Thanks guys for all
PLZ Need some help JAVA...HELP !!
PLZ Need some help JAVA...HELP !!  Create a class names Purchase Each purchase contains an invoice number, amount of sale and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set
guys,, need help,, in java programing,, arrays
guys,, need help,, in java programing,, arrays  create a program where you will input 10 numbers and arrange it in ascending way using arrays
need a java program - Java Beginners
need a java program  Draw a bar chart for the following data using frames Year: 2000 2001 2002 2003 2004 2005 TurnOver:7 8 4 5 9 12
Desperately need Java program ASAP - Java Beginners
Desperately need Java program ASAP  I need the source code for a java application that asks the user to enter a 10 character telephone number... should display 555-438-3663. I need this program ASAP if possible. Thank you
New to JSP..need help to make & run a JSP program.
New to JSP..need help to make & run a JSP program.  Hi, I have installed Tomcat 5.5 on my system. Plz help me to make a simple JSP program.... Now create a jsp file:'hello.jsp' <%@page language="java"%> <%String st
help in java program
help in java program  please could you help me with my assignment I have to submit it on Monday 29 October please help me :( Write a program to test the Person class defined below. Your test program should
help with program - Java Beginners
Help with program  Simple Java Program  // Defining class Stars.java to print stars in certain orderclass Stars{// main() functionpublic static void main(String[] args){int a = 1, b = 5, c, d, i; // declaring 5 int type
program help - Java Beginners
program help  In the following code, I want to modify class figure..., Abstract Class In java programming language, abstract classes are those.... For read more information on java visit to : http://www.roseindia.net/java
Java Question Anyone need some HELP !!
Java Question Anyone need some HELP !!  Create a file that contains... as Quote.txt. Copy the file contents and paste them into a word-processing program... of the two files. Note: For the above code, you need POI api. import
I need add my java program with a picture.
I need add my java program with a picture.  Good evng Frnds Friends i created 1 jar file in my desktop. I need add this program with 1 picture. Whenever the user double clicking on that picture The program must start instead
it possible or not
it possible or not  without public static void main(string args[]) in java program it is possible
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
need help pleaseee....i weak in java
need help pleaseee....i weak in java  QUESTION 1 You are required to write an application called Customer Billing System. This system... meter reading, current meter reading and charges. Write a structured Java program
Need help
Need help  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another drop.... This name list should get from the database. Please help me. By the way, I'm
Need Help with Java-SWING progrmming - Swing AWT
Need Help with Java-SWING progrmming  Hi sir, I am a beginner in java-swing programming. I want to know how we can use the print option with a program in swing. Could you help me with an example? Regards Sreejith 
Need help with this!
Need help with this!  Can anyone please help me... to a file at all at this time. Any help would be greatly appreciated, thank you... Program"); entry = myScanner.nextInt(); numberOfStudentsTest = 0
 

 

 

DMCA.com