Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

WorkShop 1

Part 1:

import java.util.Scanner;

public class Part01 {

public static void main (String [] arg){

int rows;

int cols;

int matrix[][];

Scanner sc = new Scanner(System.in);

System.out.println("Nhap hang : ");

rows = sc.nextInt();

System.out.println("Nhap cot : ");

cols = sc.nextInt();

matrix = new int[rows][cols];

System.out.println("Nhap ma tran[][] ");

for (int i = 0; i <rows;i++){

for(int j = 0; j < cols; j++){

System.out.print("\nm["+i+"]["+j+"]= ");

matrix[i][j]=sc.nextInt();

System.out.println("Matrix da nhap : ");

for (int i = 0; i <rows;i++){

for(int j = 0; j < cols; j++){

System.out.format("%3d", matrix[i][j]);

System.out.println("\n");

}
int sum = 0;

for (int i = 0; i <rows;i++){

for(int j = 0; j < cols; j++){

sum=sum + matrix[i][j];

System.out.println("Tong = " +sum);

System.out.println("Average:" +(float)sum/(rows*cols));

Part 2:

import java.util.Scanner;

public class Part02 {

public static void main(String [] arg){

float a,b;

String op;

Scanner sc = new Scanner(System.in);

System.out.println("Nhap so thu nhat :");

a = sc.nextFloat();

System.out.println("Nhap so thu hai :");

b = sc.nextFloat();

System.out.println("Nhap phep tinh (+-*/) :");

op = sc.nextLine();

if (op.equals("+")){

System.out.println(a + " +" +b+"=" +(a+b));

else if (op.equals("-")){

System.out.println(a + " -" +b+"=" +(a-b));

}
else if (op.equals("*")){

System.out.println(a + " *" +b+"=" +(a*b));

else{

System.out.println(a + " /" +b+"=" +(a/b));

Part 3:

import java.util.Scanner;

public class Part3 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String []list= new String[10];

System.out.println("\n\nNhập vào chuỗi cần in hoa: ");

message = sc.nextLine();

for(int i = 0; i < charArray.length; i++) {

if(charArray[i] >= 97 && charArray[i] <= 122){

charArray[i] -= 32;

System.out.println("Chuỗi sau khi in hoa: ");

System.out.println(message.toUpperCase());

System.out.println("\n---------------------------------");

You might also like