0% found this document useful (0 votes)
6 views9 pages

Java Code Snippets and Examples

The document contains multiple Java code snippets, each demonstrating different programming concepts and syntax. Some snippets include variable declarations, arithmetic operations, string manipulations, and exception handling, while others contain errors such as incorrect capitalization and syntax issues. Overall, the document serves as a collection of examples for Java programming, highlighting both correct and incorrect implementations.
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)
6 views9 pages

Java Code Snippets and Examples

The document contains multiple Java code snippets, each demonstrating different programming concepts and syntax. Some snippets include variable declarations, arithmetic operations, string manipulations, and exception handling, while others contain errors such as incorrect capitalization and syntax issues. Overall, the document serves as a collection of examples for Java programming, highlighting both correct and incorrect implementations.
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

1.

public static void main(String[]args)


{
int x =10;
[Link](x++);
}
2. public static void main(String[]args)
{
int a=10;
int b=20;
[Link](a<b?a:b);
}
[Link] static void main(String [] args)
{
String str=”hello”;
[Link]([Link]().substri
ng(1,4));
}
4) public static void main(String[] args)
{
Int[] arr={1,2,3,4,5};
[Link](arr[5]);
}
5) public static void main(String[]args)
{
Int i=0;
While (i<5)
{
i++;
}
[Link](i);
}

6) public static void main(String[]args)


{
String str=”java”;
Str=[Link](“programming”);
[Link](str);
}
7) public static void main(String[] args)
{
int a=10;
int b=0;
try
{
[Link](a/b);
}
Catch(ArithmeticException e)
{
[Link](“Error”); } } }
[Link] static void main(String args[])
{
String s=”123”;
int num=[Link](s);
[Link](num);
}
9. public static void main(String args[])
{
for(int i=0;i<3;i++)
{
[Link](i);
}
}
[Link] static void main(String args[])
{
int a=5;
int b=a++;
[Link](b);
}

11. public static void main(String args[])


{
String s=”hello”;
S=[Link](‘I’,’r’);
[Link](s);
}
12. public static void main(String args[])
{
String[] arr=new String[5];
arr[0]=”one”;
arr[1]=”two”;
[Link](arr[2]);
}
13. public static void main(String args[])
{
String str=”java”;
[Link]([Link](1,4));
}
[Link] static void main(String args[])
{
Int i=1;
[Link](i++ + ++i);
}
15. public static void main(String args[])
{
[Link](“Hello” +1+2);
}
16. public static void main(String args[])
{
String str=”java”;
[Link]([Link](2));
}
17. public static void main(String args[])
{
int[] nums=new int[]{1,2,3};
for(int i:nums)
{
[Link](i);
}
}
18. public static void main(String args[])
{
String s=”abc”;
S=[Link]();
[Link](s);
}
19. public static void main(String args[])
{
String s=”123a”;
Int num=[Link](s);
[Link](num);
}
20. public static void main(String args[])
{
int a=5;
int b=10;
[Link](++a*b--);
}

You might also like