• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Day-43:Maximum and minimum and Dimensional Array

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Notes1:


package Array;

public class MaxValue {
public static void main(String[] args) {
int[] marks = {88,73, 82,88,95};
int max = 0;
for(int i=0; i<marks.length; i++)
{
if(marks>max)
max = marks;
}
System.out.println(max);
}
}

output:
95

Notes2:


package Array;

public class MaxValue2 {
public static void main(String[] args) {
int[] marks = {-188,-873, 1082,788,995};
int max = Integer.MIN_VALUE;
for(int i=0; i<marks.length; i++)
{
if(marks>max)
max = marks;
}
System.out.println(max);
}
}

output:
1082

Notes3:


package Array;

public class MaxValue3 {
public static void main(String[] args) {
int[] marks = {95,97,96,100,99};
int max = marks[0];
int second_max = marks[0];
for(int i=1; i<marks.length; i++)
{
if(marks>max)
{
second_max = max;
max = marks;
}
else if(marks> second_max)
{
second_max = marks;
}
}
System.out.println(max);
System.out.println(second_max);
}
}

output:
100
99

Notes4:


package Array;

public class MaxValue4 {

public static void main(String[] args) {
// TODO Auto-generated method stub
int[] marks = {-95,-97,-96,-100,-99};
int max = Integer.MIN_VALUE;
int second_max = Integer.MIN_VALUE;
for(int i=0; i<marks.length; i++)
{
if(marks>max)
{
second_max = max;
max = marks;
}
else if(marks> second_max)
{
second_max = marks;
}
}
System.out.println(max);
System.out.println(second_max);
}

}

output:
-95
-96

Notes5:


package Array;

public class MinValue {
public static void main(String[] args) {
int[] marks = {88,73, 82,88,95};
int min = 100;
for(int i=0; i<marks.length; i++)
{
if(marks<min)
min = marks;
}
System.out.println(min);
}

}

output:
73

Notes6:


package Array;

public class MinValue2 {
public static void main(String[] args) {
int[] marks = {-188,-873, 1082,788,995};
int min = Integer.MAX_VALUE;
for(int i=0; i<marks.length; i++)
{
if(marks<min)
min = marks;
}
System.out.println(min);
}
}

output:
-873

Notes7:


package Array;

public class Dimension {
public static void main(String[] args) {
int [] a = {10,20,30,40};
int[] b = {40,50,60,70};
int[] c = {70,80,90,100};

int[][] ar = {a,b,c};
System.out.println(ar.length);

System.out.print(ar[0][0] + " "+ar[0][1]+" "+ar[0][2]+ " "+ar[0][3]);
System.out.println();
System.out.print(ar[1][0] + " "+ar[1][1]+" "+ar[1][2]+ " "+ar[1][3]);
System.out.println();
System.out.print(ar[2][0] + " "+ar[2][1]+" "+ar[2][2]+ " "+ar[2][3]);


}
}

output:
3
10 20 30 40
40 50 60 70
70 80 90 100

Notes8:


package Array;

public class Dimension2 {
public static void main(String[] args) {
int [] a = {10,20,30,40};
int[] b = {40,50,60,70};
int[] c = {70,80,90,100};

int[][] ar = {a,b,c};
System.out.println(ar.length);
int row=0;
System.out.print(ar[row][0] + " "+ar[row][1]+" "+ar[row][2]+ " "+
ar[row][3]);
System.out.println();
row++;
System.out.print(ar[row][0] + " "+ar[row][1]+" "+ar[row][2]+ " "+
ar[row][3]);
System.out.println();
row++;
System.out.print(ar[row][0] + " "+ar[row][1]+" "+ar[row][2]+ " "+ar[row][3]);

}
}

output:
3
10 20 30 40
40 50 60 70
70 80 90 100

Notes9:


package Array;

public class Dimension3 {
public static void main(String[] args) {
int [] a = {10,20,30,40};
int[] b = {40,50,60,70};
int[] c = {70,80,90,100};

int[][] ar = {a,b,c};
System.out.println(ar.length);

for(int row=0; row<ar.length; row++)
{
System.out.print(ar[row][0] + " "+ar[row][1]+" "+ar[row][2]+ " "+
ar[row][3]);
System.out.println();
}

}
}

output:
3
10 20 30 40
40 50 60 70
70 80 90 100

Notes10:


package Array;

public class Dimension4 {

public static void main(String[] args) {
// TODO Auto-generated method stub
int [] a = {10,20,30,40};
int[] b = {40,50,60,70};
int[] c = {70,80,90,100};
System.out.println(a.length);

int[][] ar = {a,b,c};
for(int col=0; col<ar[0].length; col++)
System.out.print(ar[0][col]+" ");
System.out.println();
for(int col=0; col<ar[1].length; col++)
System.out.print(ar[1][col]+" ");
System.out.println();
for(int col=0; col<ar[2].length; col++)
System.out.print(ar[2][col]+" ");
}

}

output:
3
10 20 30 40
40 50 60 70
70 80 90 100

Notes11:


package Array;

public class Dimension5 {
public static void main(String[] args) {
int [] a = {10,20,30,40};
int[] b = {40,50,60,70};
int[] c = {70,80,90,100};
System.out.println(a.length);

int[][] ar = {a,b,c};
int row = 0;
for(int col=0; col<ar[row].length; col++)
System.out.print(ar[row][col]+" ");
System.out.println(); row++;
for(int col=0; col<ar[row].length; col++)
System.out.print(ar[row][col]+" ");
System.out.println();row++;
for(int col=0; col<ar[row].length; col++)
System.out.print(ar[row][col]+" ");
}
}

output:
4
10 20 30 40
40 50 60 70
70 80 90 100

Notes12:


package Array;

public class Dimension6 {
public static void main(String[] args) {
int [] a = {10,20,30,40};
int[] b = {40,50,60,70};
int[] c = {70,80,90,100};
System.out.println(a.length);

int[][] ar = {a,b,c};
for(int row = 0; row<ar.length; row++)
{
for(int col=0; col<ar[row].length; col++)
{
System.out.print(ar[row][col]+" ");
}
System.out.println();
}
}
}

output:
4
10 20 30 40
40 50 60 70
70 80 90 100

Task:
int[] ar = { {10,20,30}, {40,50,60}, {70,80,90}};

1) Print only first column values - 10,40,70


package Array;

public class Task5 {
public static void main(String[] args) {



int[][] ar = {{10,20,30},{40,50,60},{70,80,90}};
System.out.println(ar.length);

for (int i = 0; i < ar.length; i++) {
System.out.println(ar[0]);
}


}
}

output:
3
10
40
70

2) Calculate sum of diagonal values - 10+50+90


package Array;

public class Task6 {
public static void main(String[] args) {
int[][] ar = {{10,20,30},{40,50,60},{70,80,90}};

int total=0;
for (int i = 0; i < ar.length; i++) {
System.out.println(ar);
total=total+(ar);
}

System.out.println(total);
}
}

output:
10
50
90
150

3) Sum of each row


package Array;

public class Task7 {
public static void main(String[] args) {
int[][] ar = {{10,20,30},{40,50,60},{70,80,90}};

int total=0;
for(int row = 0; row<ar.length; row++)
{
for(int col=0; col<ar[row].length; col++)
{
System.out.print(ar[row][col]+" ");
total=total+(ar[row][col]);
}
System.out.println();
System.out.println(total);
}
}
}

output:
10 20 30
60
40 50 60
210
70 80 90
450


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу