0% found this document useful (0 votes)
19 views3 pages

WorkShop 1

The document contains code for 3 Java programs. Part 1 defines a method to input and output a 2D array and calculate the sum and average of elements. Part 2 defines a method to input 2 numbers and an operator, perform the calculation, and output the result. Part 3 defines a method to input a string, convert it to uppercase, and output the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

WorkShop 1

The document contains code for 3 Java programs. Part 1 defines a method to input and output a 2D array and calculate the sum and average of elements. Part 2 defines a method to input 2 numbers and an operator, perform the calculation, and output the result. Part 3 defines a method to input a string, convert it to uppercase, and output the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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