You are on page 1of 5

JAVA 1- UTS APPLICATION CODES

QUESTION 1
package utsq01;
import java.io.*;

public class UtsQ01 {

public static void main(String[] args)throws Exception {


BufferedReader reader=new BufferedReader (new InputStreamReader(System.in));
System.out.println("Hello there! This is a program that converts time in seconds to Hours, Minutes
and Seconds.");
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("By: Philippa Joumkalop");
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("Please enter total time in seconds.");
double time=Double.parseDouble(reader.readLine());

System.out.println("The total time after being converted is....");


int hours=(int)time/3600;
System.out.println(hours + " Hour(s)");

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;

public class UtsQ02 {

public static void main(String[] args){

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("------------------------------------------------------------------------------------------");

Scanner sc=new Scanner(System.in);


System.out.println("Please enter the length of the base of the triangle: ");
base=sc.nextInt();

System.out.println("Please enter the height of the triangle: ");


height=sc.nextInt();

area=(base*height)/2;
System.out.println("The Area of the triangle is; " + area);

Double hypotenuse = Math.pow(Math.pow(base, 2) + Math.pow(height, 2),0.5);

Double perimeter = base + height + hypotenuse;

System.out.println("The perimeter of the triangle is " + perimeter);


sc.close();
}
}

QUESTION 3
package utsq03;
import java.util.Scanner;

public class UtsQ03 {


public static void main(String[] args){
System.out.println("Hello there! This is a program that finds the smallest number from five given
integers.");
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("By: Philippa Joumkalop");
System.out.println("------------------------------------------------------------------------------------------");
int value[]=new int[5];
int x,i;
Scanner data=new Scanner(System.in);
System.out.println("Please enter five integer numbers.");

for (i=0; i<5; i++)


value[i]=data.nextInt();

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 {

public static void main(String[] args) {

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;

System.out.print(Elements +" ");

}
}
}
}

You might also like