Add Two Number Get link Facebook X Pinterest Email Other Apps February 11, 2019 Write a java program to add two numbers class Add { public static void main(String[] args) { int a=5; int b=10; int c=a+b; System.out.println("Sum of "+a+" and "+b+" is :"+c); } } Get link Facebook X Pinterest Email Other Apps Comments
February 14, 2019 Write a java program to print following pattern:- A ABA ABCAB ABCDABC import java.util.Scanner; public class CharPattern20 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter Row size : "); int n=sc.nextInt(); for(int i=0;i<n;i++) { int k=1,l=2*i-1; for(int j=0;j<n-i;j++) { System.out.print(" "); } for(int j=0;j<l;j++) { System.out.print((char)(64+k++)+""); if(j==i-1) k=1; } System.out.println(); } } } Read more
February 12, 2019 Write a java program to print following number pattern 1 2 3 4 5 11 12 13 14 15 21 22 23 24 25 16 17 18 19 20 6 7 8 9 10 import java.util.Scanner; public class NumberPattern { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter Size: "); int n=sc.nextInt(); int k=0,l=1; for (int i = 1; i <= n; i++) { if(i <= n/2+1) { if(i!=1) k=k+2; } else { if (k%2==0) { k--; } else { k=k-2; } } for (int j = 1; j <= n; j++) { System.out.print((k*n+j)+" "); } System.out.println(); } } } Read more
February 12, 2019 Write a java program to print following pattern:- 1 3 2 4 5 6 10 9 8 7 11 12 13 14 15 import java.util.Scanner; public class CountPattern31 { static Scanner sc=new Scanner(System.in); public static void main(String[] args) { System.out.println("Enter Size : "); int n=sc.nextInt(); int k=1; for(int i=1;i<=n;i++) { int l=k+i-1; for(int j=1;j<=i;j++) { if (i%2 != 0) { System.out.print(k+" "); } else { System.out.print(l+" "); } k++; l--; } System.out.println(); } } } Read more
Comments
Post a Comment