Variable Listing for Java Programs (with
Scope)
1) Twisted Prime
Variable Name Data Type Purpose Scope
n int Stores the input Local
number
sc Scanner To take input from Local
user
r int Stores the reverse of Local
the number
i int Loop control Local
variable
c int Counts factors for Local
prime check
2) Abundant Number
Variable Name Data Type Purpose Scope
l int Lower range input Local
u int Upper range input Local
sc Scanner To take input from Local
user
i int Loop control Local
variable
s int Stores sum of Local
factors
n int Number to check Parameter
abundant
3) Sum of Largest and Smallest Digit
Variable Name Data Type Purpose Scope
n int Stores 5-digit input Local
number
sc Scanner To take input Local
l int Stores largest digit Local
s int Stores smallest digit Local
c int Counts factors to Local
check composite
i int Loop control Local
variable
4) Switch Pattern
Variable Name Data Type Purpose Scope
n int Choice for pattern Local
type
sc Scanner To take input Local
l int Number of lines Local
i int Outer loop counter Local
j int Inner loop counter Local
5) Series Pattern Sum
Variable Name Data Type Purpose Scope
a int Stores value of a Parameter
n int Number of terms Parameter
sum double Stores sum of series Local
fact double Stores factorial Local
value
sign int Stores +1/-1 for Local
alternating sign
i int Loop control Local
variable
j int Loop control for Local
factorial
6) Pattern Overload
Variable Name Data Type Purpose Scope
r int Number of rows Instance
x char Character for Instance
pattern
rows int User input for rows Local
character2 char User input character Local
choice int Menu choice Local
i int Loop variable Local
j int Nested loop variable Local
k int Used for increment Local
in pattern
8) Bill Program
Variable Name Data Type Purpose Scope
bno int Bill number Instance
call int Number of calls Instance
amt double Bill amount Instance
name String Customer name Instance
b int User entered bill Local
number
calls int User entered calls Local
n String User entered name Local
9) Largest, 2nd Largest, Square Root Sum
Variable Name Data Type Purpose Scope
n int Array size Local
a[] int[] Array of elements Local
sc Scanner To take input Local
max int Largest element Local
min int Smallest element Local
max2 int Second largest Local
element
s int Sum of positive Local
numbers
i int Loop control Local
variable
10) Merge Two Arrays
Variable Name Data Type Purpose Scope
m int Size of first array Local
n int Size of second array Local
P[] int[] First array Local
Q[] int[] Second array Local
R[] int[] Merged array Local
k int Index for merged Local
array
i int Loop control Local
t int Temporary variable Local
for swapping
min int Index of smallest Local
element