Cathy Dinh
need help with java program as soon as possible
1 Answer(s)      4 years and 6 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
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 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
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
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 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
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