import java.util.*; public class CPP{ public static void main(String []args){ Scanner sc = new Scanner(System.in); int no_of_vertices=sc.nextInt(); int no_of_edges=sc.nextInt(); int node1, node2, cost; for(int i=0;i<no_of_edges;i++){ node1=sc.nextInt(); node2=sc.nextInt(); cost=sc.nextInt(); } } }
package com.india.sachin; import java.util.*; import java.util.stream.*; class Student { int age; String name; int marks; public Student(int age,String name,int marks) { this.age=age; this.name=name; this.marks=marks; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getMarks() { return marks; } public void setMarks(int marks) { this.marks = marks; } } public class HelloWorld { public static void main(String[] args) { ArrayList<Student> al=new ArrayList<Student>(); al.add(new Student(27,"sachin",78)); al.add(new Student(26,"nitin",45)); /* al.forEach((n)->System.out.println(n.age+" "+n.name)); al.forEach( (m)->System.out.println(m.marks) ); */ /* al.stream().filter(p->p.age>26).forEach((p)->System.out.println(p.age+" "+p.name+" "+p.marks)); */ Set<Integer> set=al.stream().filter(p->p.age>26).map(p->p.age).collect(Collectors.toSet()); for(int a:set) { // System.out.println(a); } Set<Student> set1=al.stream().sorted(new Comparator<Student>() { public int compare(Student s1,Student s2) { if(s1.getAge()<s2.getAge()) { return 1; } else if(s1.getAge()>s2.getAge()) { return -1; } else { return 0; } } } ).collect(Collectors.toSet()); set1.forEach((n)->System.out.println(n.age+" "+n.name+" "+n.marks)); Map<Integer,String> ma=al.stream().collect(Collectors.toMap(m->m.age,m->m.name)); System.out.println(ma); } }
public class InsertionSorter { public static int sort(int[] randi) { if (randi == null || randi.length == 0) { return 0; } int count = 0; //int n = randi.length; for (int i = 1; i < randi.length; ++i) { int pivot = randi[i]; int j = i - 1; while (j >= 0 && randi[j] > pivot) { count++; randi[j + 1] = randi[j]; j = j - 1; } randi[j + 1] = pivot; } System.out.println("count: " + count); System.out.println(); return count; } static void printArray(int arr[]) { //int n = arr.length; for (int i = 0; i < arr.length; ++i) System.out.print(arr[i] + " "); System.out.println(); } // Driver method public static void main(String args[]) { int arr[] = { 12, 11, 13, 5, 6, 8, 20 }; InsertionSorter ob = new InsertionSorter(); ob.sort(arr); printArray(arr); } }
public class ExceptionExam3 { public static void main(String[] args) { int i = 10; int j = 0; try{ int k = divide(i, j); System.out.println(k); }catch(IllegalArgumentException e){ System.out.println("0으로 나누면 안됩니다."); } } public static int divide(int i, int j) throws IllegalArgumentException{ if(j == 0){ throw new IllegalArgumentException("0으로 나눌 수 없어요."); } int k = i / j; return k; } }
public class BoxDemo { public static void main(String []args) { Box b1=new Box(); b1.height=5; b1.length=10; b1.breadth=6; b1.volume(); } } class Box { int length,breadth,height; public void volume() { int vol; vol=length*height*breadth; System.out.println("vol of the box="+vol); } }
public class HelloWorld{ public static void main(String []args){ int num1=70; int num2=70; int num3=70; if(num1>num2 && num1>num3){ System.out.println(num1); } else if(num2>num1 && num2>num3){ System.out.println(num2); } else if(num3>num1 && num3>num2){ System.out.println(num3); } else { System.out.println(" the number are equal "); } } }
public class HelloWorld{ public static void main(String []args){ System.out.println("Hello World"); } }
public class HelloWorld{ public static void main(String []args){ System.out.println("Hello World"); int num1 = 10; int num2 = 90; int num3 = 100; if(num1>num2 && num1 > num3 ){ System.out.println("largest number is:"+num1); } else if(num2 > num3 && num2 > num1 ){ System.out.println("largest number is:"+num2); } else if(num3 > num1 && num3 > num2){ System.out.println("largest number is:"+num3); } else{ System.out.println("no.are equal"); } } }
package metodo.de.la.burbuja; public class MetodoDeLaBurbuja { public static int[] burbuja(int[] arreglo) { int auxiliar; int[] arregloOrdenado; for(int i = 2; i < arreglo.length; i++) { for(int j = 0;j < arreglo.length-i;j++) { if(arreglo[j] > arreglo[j+1]) { auxiliar = arreglo[j]; arreglo[j] = arreglo[j+1]; arreglo[j+1] = auxiliar; } } } arregloOrdenado = arreglo; return arregloOrdenado; } public static void main(String[] args) { int arreglo[] = {8,6,7,2,1,8,6,8,7,1,9,7,7,10}; int arregloOrdenado[] = burbuja(arreglo); for(int i = 0; i < arregloOrdenado.length;i++) System.out.println(arregloOrdenado[i]); } }
/* 1. Replace following sentence with “Mercedes best german car” to “BMW best german car” */ public class HelloWorld { public static void replace(){ String Text = "Mercedes is the best German car!"; String change = "Mercedes"; String replace = "BMW"; System.out.println(Text.replace(change, replace)); } public static void main(String []args) { replace(); } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more