You are on page 1of 8

IAN L.

TAREGA
BSIT-2C
ACTIVITY NO.1 – JAVA PRACTICE PROBLEMS

1.PNG
package act_ouputs;

import java.util.Scanner;

public class Act_Ouputs {

public static void main(String[] args) {

int num1, num2;

Scanner output = new Scanner


(System.in);

System.out.println("Enter value for num1:");

num1 = output.nextInt();

System.out.println("Enter value for num2:");

num2 = output.nextInt();

if(num1 > num2){

System.out.println("num1 is greater than num2");

}else if(num1 < num2){

System.out.println("num2 is greater than num1");

} else {

System.out.println("Both have equal value");

}
2.PNG
package act_ouputs;

import java.util.Scanner;

public class Act_Ouputs {

public static void main(String[] args) {

Scanner output = new Scanner (System.in);

String name;

int math, science, history, ss;

System.out.println("Enter student name: ");

name = output.nextLine();

System.out.println("Enter Mark in Math: ");

math = output.nextInt();

System.out.println("Enter Mark in Science: ");

science = output.nextInt();

System.out.println("Enter Mark in History: ");

history = output.nextInt();

System.out.println("Enter Mark in Social Studies: ");

ss = output.nextInt();

int sum = math+science+history+ss;

float pt = (float)sum/4;

System.out.println("Total Marks: "+sum);

System.out.println("Percentage: "+pt);
if(pt < 75){

System.out.println("Status: Failed\n");

System.out.println("Sorry "+name+" better luck next time!");

}else{

System.out.println("Status: Passed\n");

System.out.println("Congrats "+name);

3.PNG
package act_ouputs;

import java.util.Scanner;

public class Act_Ouputs {

public static void main(String[] args) {

Scanner output = new Scanner (System.in);

String name;

int quan, price, sold, still;

System.out.println("Enter number of products:


");

quan = output.nextInt();

System.out.println("Enter price per product: ");

price = output.nextInt();
System.out.println("Number of sold products: ");

sold = output.nextInt();

System.out.println("Enter remaining products: ");

still = output.nextInt();

int total, loss, profit, loss1;

total = sold*price;

loss = quan-sold;

loss1 = (loss-still)*price;

profit = quan*price;

System.out.println("Total Profit: "+total);

System.out.println("Total Loss: "+loss1);

System.out.println("Expected Profit: "+profit);

4.PNG

package act_ouputs;

import java.util.Scanner;

public class Act_Ouputs {

public static void main(String[] args) {

Scanner output = new Scanner (System.in);

String fname, lname;


int year;

System.out.println("Enter firstname: ");

fname = output.nextLine();

System.out.println("Enter lastname: ");

lname = output.nextLine();

System.out.println("Enter birthdate: ");

year = output.nextInt();

int age = 2022-year;

System.out.println("\nHello " +fname+" "+lname);

if(age >= 18){

System.out.println("Your Age is "+age+" years old and of legal age");

}else{

System.out.println("Your Age is "+age+" years old and of minor age");

5.SLIDE2.PNG
package act_ouputs;

import java.util.Scanner;
public class Act_Ouputs {

public static void main(String[] args) {

Scanner output = new Scanner (System.in);

String fname, lname;

int year;

System.out.println("Enter firstname: ");

fname = output.nextLine();

System.out.println("Enter lastname: ");

lname = output.nextLine();

System.out.println("Enter birthdate: ");

year = output.nextInt();

int age = 2022-year;

System.out.println("\nHello " +fname+" "+lname);

System.out.println("Your Age is "+age+" years old ");

6.SLIDE3.PNG
package act_ouputs;

import java.util.Scanner;
public class Act_Ouputs {

public static void main(String[] args) {

Scanner output = new Scanner (System.in);

float height, width;

System.out.println("Input the height of the rectangle: ");

height = output.nextInt();

System.out.println("Enter the width of the rectangle: ");

width = output.nextInt();

float tot = (float)height + (float)width;

float perimeter = (float)2*tot;

System.out.println("Perimeter of the Rectangle: "+perimeter);

7.SLIDE4.PNG
package act_ouputs;

import java.util.Scanner;
public class Act_Ouputs {

public static void main(String[] args) {

Scanner output = new Scanner (System.in);

int mins, hr, min;

System.out.println("Enter number of minutes: ");

mins = output.nextInt();

hr = mins/60;

min = mins%60;

System.out.println("Total hours "+hr+" and "+min+" minutes");

You might also like