Professional Documents
Culture Documents
QUESTION 1
package utsq01;
import java.io.*;
int mins=(int)(time-hours*3600)/60;
System.out.println(mins + " Minute(s)");
int seconds=(int)(time-hours*3600-mins*60);
System.out.println(seconds + " Second(s)");
}
}
QUESTION 2
package utsq02;
import java.util.Scanner;
int base;
int height;
int area;
System.out.println("Hello there! This is a program that calculates the area and perimeter of a
triangle.");
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("By: Philippa Joumkalop");
System.out.println("------------------------------------------------------------------------------------------");
area=(base*height)/2;
System.out.println("The Area of the triangle is; " + area);
QUESTION 3
package utsq03;
import java.util.Scanner;
x=value[0];
for (i=0; i<5; i++)
{
if (x<value[i])
else
x=value[i];
}
System.out.println("The smallest number in the group is: " + x);
}
}
QUESTION 4
package utsq04;
import java.util.Scanner;
public class UtsQ04 {
System.out.println("Hello there! This is a program that prints series of 5 with the term entered by the
user.");
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("By: Philippa Joumkalop");
System.out.println("------------------------------------------------------------------------------------------");
int input;
int x=5;
Scanner Keyboard=new Scanner(System.in);
System.out.print("Please enter the number of terms for the series:");
input=Keyboard.nextInt();
System.out.println("The series of "+ x +" using "+ input +" terms are: ");
Test(input);
}
public static void Test (int input){
if (input == 0) {
System.out.println("0");
} else if (input == 5) {
System.out.println("0 5");
} else {
System.out.print("0 ");
int a=0;
int b=5;
int Elements;
int i;
for(i = 1;i < input;i++){
Elements = a + b ;
a = b + a;
}
}
}
}