Professional Documents
Culture Documents
String n="a1b10";
char a[];
char charValue = 0;
int i,j,count=0,numberValue=0;
a=n.toCharArray();
for(i=0;i<a.length;i++) {
if(Character.isDigit(a[i]))
{
while(Character.isDigit(a[i]))
{
numberValue=Character.getNumericValue(a[i]);
count=(count*10)+numberValue;
i++;
if(i>(a.length-1))
{
i--;
break;
}
}
while(Character.isAlphabetic(a[i]))
{
i--;
break;
}
for(j=0;j<count;j++) {
System.out.print(charValue+" ");
}
count=0;
}
else
{
charValue=a[i];
}
}
}
}
======================================
public class CrossPattern {
j=a.length()-1;
char[] charArray=a.toCharArray();
for(int i=0;i<a.length();i++)
{
for(int k=0;k<a.length();k++)
{
if(k==i)
{
System.out.print(charArray[k]+" ");
}
else if(k==j){
System.out.print(charArray[k]+" ");
}
else
{
System.out.print(" ");
}
}
System.out.println("");
j--;
}
}
}
============================
DIAMOND PATTERN
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int n, i, j, space = 1;
System.out.print("Enter the number of rows: ");
Scanner s = new Scanner(System.in);
n = s.nextInt();
space = n - 1;
for (j = 1; j <= n; j++)
{
for (i = 1; i <= space; i++)
{
System.out.print(" ");
}
space--;
for (i = 1; i <= 2 * j - 1; i++)
{
System.out.print("*");
}
System.out.println("");
}
space = 1;
for (j = 1; j <= n - 1; j++)
{
for (i = 1; i <= space; i++)
{
System.out.print(" ");
}
space++;
for (i = 1; i <= 2 * (n - j) - 1; i++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
==========================
MATRIX
import java.util.*;
import java.lang.*;
// driver function
public static void main(String argc[]){
int[][] mat= { { 1,0},
{1,1}};
if (isUpperTriangularMatrix(mat))
System.out.println("Upper Triangular Matrix");
else
System.out.println("Lower Triangular Matrix");
}
}
==================================
2)
import java.util.Scanner;
int k =0 , l =0;
for(int i=0; i<size; i++)
{
if(i%2 == 0)
{
descend[k] = arr[i];
k++;
}
else
{
ascend[l] = arr[i];
l++;
}
}
k =0;
l =0;
for(int i=0; i<size; i++)
{
if(i%2 == 0)
{
System.out.print(descend[k]+",");
k++;
}
else
{
System.out.print(ascend[l]+",");
l++;
}
}
}
}
================================
4)
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
String str1,str2;
}
if(signal == 1)
System.out.println("-1");
}
}
=================================
5)
import java.util.Scanner;