-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrange.java
44 lines (41 loc) · 846 Bytes
/
range.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
class sqlist
{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int ul,ll;
System.out.print("Enter the lower limit: ");
ll=sc.nextByte();
System.out.print("Enter the upper limit: ");
ul=sc.nextByte();
if(ll>ul)
{
System.out.print("Enter the valid limits");
}
if(ll<0 ||ul<0 ||(ll<0 &&ul<0 ))
{
System.out.print("Enter the valid limits");
}
else
{
System.out.print("[");
if(ll<ul){
for(int j=ll;j<=ul;j++){
System.out.print("("+j+","+(int)Math.pow(j,2)+")");
if(j<ul)
System.out.print(",");
}
}
if(ul<ll){
for(int i=ll;i>=ul;i--){
System.out.print("("+i+","+(int)Math.pow(i,2)+")");
if(i>ul)
System.out.print(",");
}
}
System.out.print("]");
if(ul==ll)
System.out.println("Both the limits are same");
}
}
}