Nits
BAN USERpackage test;
public class ProductArray {
/**
* @param args
*/
public static void main(String[] args) {
int [] array = {4,2,5,1};
int [] b = getArray(array);
for(int i = 0;i<array.length;i++){
System.out.println(b[i]);
}
}
private static int [] getArray(int [] array){
int [] b = new int[array.length];
int mult = 1;
for(int i = array.length-1;i>=0;i--){
for(int j = array.length-1;j>=0;j--){
if(i!=j){
mult*=array[j];
}
}
b[i] = mult;
mult =1;
}
return b;
}
}
public class CircularShiftArray {
public static void main(String[] args) {
int[] array = {2,5,1,8,10};
shiftArray(array,2);
}
private static void shiftArray(int[] array, int n){
int length = array.length;
int i =0,temp = array[0],temp2 =0, count = 0;
while(count!=length){
int newIndex = (i+n)%length;
temp2 = array[newIndex];
array[newIndex] = temp;
temp = temp2;
count++;i = newIndex;
}
}
}
- Nits November 10, 2013package test;
public class ZigZagReverse {
public static void main(String[] args) {
String input[] = { "zig", "zag", "reverse", "string" };
ZigZagReverse zigZagReverse = new ZigZagReverse();
for (int i = 0; i < input.length; i++) {
String s = input[i];
input[i] = zigZagReverse.reverse(s, i);
}
zigZagReverse.displayOutput(input);
}
/* method to display the output */
private void displayOutput(String[] output) {
for (int i = 0; i < output.length; i++) {
System.out.print(output[i] + " ");
}
}
/* method to reverse a string */
private String reverse(String s, int i) {
int start, end;
char temp;
if (i % 2 == 0) {
char array[] = s.toCharArray();
start = 0;
end = array.length - 1;
while (start < end) {
temp = array[start];
array[start] = array[end];
array[end] = temp;
start++;
end--;
}
s = new String(array);
}
return s;
}
}
public static void main(String[] args) {
SecondMax secondMax = new SecondMax();
int [] array = {7,4,6,4,7};
int secondMaxValue = secondMax.getSecondMax(array);
System.out.println("The second max number in the array " + secondMaxValue);
}
private int getSecondMax(int [] array){
int max = Integer.MIN_VALUE;
int smax = Integer.MIN_VALUE;
for(int i =0;i<array.length;i++){
if(array[i] >max ){
max= array[i];
}
else if(smax< array[i]&& array[i]<max){
smax = array[i];
}else continue;
}
return smax;
}
}
- Nits March 17, 2013public class SecondMax {
/**
* @param args
*/
public static void main(String[] args) {
SecondMax secondMax = new SecondMax();
int [] array = {10,4,6,4,7};
int secondMaxValue = secondMax.getSecondMax(array);
System.out.println("The second max number in the array " + secondMaxValue);
}
private int getSecondMax(int[] array){
int max = Integer.MIN_VALUE;
for(int i =0; i<array.length;i++){
if(array[i] > max)
max = array[i];
}
int difference = 0;
int secondMax =0;
int value = Integer.MAX_VALUE;
for(int i =0; i<array.length;i++){
difference = max - array[i];
if(difference < value && difference !=0){
value = difference;
secondMax = array[i];
}
}
return secondMax;
}
public static void main(String[] args) {
String s = new Integer(12521).toString();
StringPalindrome stringPalindrome = new StringPalindrome();
System.out.println(stringPalindrome.checkPalindrome(s,0,s.length()-1));
}
private boolean checkPalindrome(String s,int start, int end ){
while(start <= end){
if(s.charAt(start) == s.charAt(end)){
start++;end--;
}else return false;
}
return true;
}
public class ReverseArray {
public static void main(String[] args) {
String s = "this is a test";
char[] array = s.toCharArray();
ReverseArray reverseArray = new ReverseArray();
int count = reverseArray.count(array);
StringBuffer[] string = new StringBuffer[count];
for(int k =0;k<string.length;k++){
string[k]= new StringBuffer();
}
int j =0;
for(int i =0;i<array.length;i++){
if(array[i]!= ' '){
string[j].append(array[i]);
}
else{
j++;
}
}
for(int g=0;g<string.length;g++){
System.out.print(" " +string[g]);
}
System.out.println();
for(int g=string.length-1;g>=0;g--){
System.out.print(" " +string[g]);
}
}
//counting the number of elements in the string
public int count(char[] array){
int count=0;
for(int i =0;i<array.length;i++){
if(array[i] == ' '){
count++;
}
}
return count+1;
}
}
It can be assumed that we have three tables
1) Student (S_Id, S_firstname, S_lastname)
2)Student_Course(S_Id,Course_Id,grades)
3)Course_Year(Course_Id,year)
S_Id : Student ID
S_firstname : student firstname
S_lastName : student lastName
Course_Id : course ID
grades : grade of the student in that course
year : to tell the course is a sophomore or junior or senior course
- Nits November 18, 2013