import java.io.*;
public class Lagare4{
public static void main(String []args){
BufferedReader DataIn= new BufferedReader(new InputStreamReader(System.in));
String choice="N";
do
{
int str=0;
int end=0;
String num1="";
String num2="";
int sum=0;
int n=0;
System.out.print("Please enter the starting number: ");
try{
num1=DataIn.readLine();
str=Integer.parseInt(num1);
}catch( IOException e ){
System.out.println("Error!");
}
System.out.print("Please enter the last number: ");
try{
num2=DataIn.readLine();
end=Integer.parseInt(num2);
}catch( IOException e ){
System.out.println("Error!");
}
int[]last=new int[end+1];
if(str>=end)
{
System.out.println("Error: Starting number is greater than last number");
System.out.println();
}
else
for( int i=str; i<last.length; i++ )
{
if(i%2==1)
System.out.println(last[i]=i);
sum=last[i]+sum;
}
System.out.println("The sum of all odd numbers is "+sum);
System.out.println("Do it again? (Y/N)");
try{
choice=DataIn.readLine();
}catch( IOException e ){
System.out.println("Error!");
}
}while(!choice.equalsIgnoreCase("N"));
}
}
hello.txt (354bytes)
Number of downloads: 159
hello.txt (354bytes)
Number of downloads: 159

New Topic/Question
Reply




MultiQuote





|