COSC201101052 - Assignment 1
COSC201101052 - Assignment 1
Program # 1:
Write a program that displays counting from 1 to 10, and from 10 to 1. Using
while loop.
int c = 10;
import java.util.Scanner;
import java.util.Scanner;
c = s;
do
{
if(c%2!=0)
System.out.println(c);
c++;
}
while(c<=e);
}
}
Program # 6:
Write a program that gets two numbers from the user and displays the result
of first number raise to the power of second number using for loop.
import java.util.Scanner;
r=1;
for(c=1; c<=b; c++)
{
r = r*a;
}
import java.util.Scanner;
import java.util.Scanner;
for(n=1; n!=-1; )
{
System.out.print("Enter a number: ");
n = input.nextInt();
System.out.println("You entered " + n);
}
System.out.print("End of Program..");
}
}
Program # 9:
Write a program to get an integer from a user and reverse it. This program
should assume that user inputs positive integer only. Use While loop.
import java.util.Scanner;
import java.util.Scanner;
Program # 1:
Write a program that inputs an integer (say n) from user, Then calculate the
sum of squares of integers up to n. (i.e., sum = 12 + 22 + 32 + … + n2).
import java.util.Scanner;
import java.util.Scanner;
for(int a=0;a>=0;a++)
{
System.out.print("Enter a number : ");
n = input.nextInt();
if(n>max)
max=n;
if(n<min)
min=n;
if(choice=='y' || choice=='Y')
continue;
else
break;
}
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;