0% found this document useful (0 votes)
15 views6 pages

gr8 Part1javaprogramwsanswerkey

Uploaded by

nannuirene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

gr8 Part1javaprogramwsanswerkey

Uploaded by

nannuirene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

INTRODUCTION TO JAVA

PROGRAMS WORKSHEET-PART- 1/ANSWER KEY

1..Write a JAVA program to print To display the message “Welcome to Java Programming!!”
public class Message1
{
public static void main(String args[ ])
{
System.out.println("Welcome to Java Programming!!” );
}
}

2.Write a JAVA program to print the pattern as shown below.

public class RightTrianglePattern


{
public static void main(String args[])
{
System.out.print("*\n");
System.out.print("**\n");
System.out.print("***\n");
System.out.print("****\n");
System.out.print("*****\n");
System.out.print("******\n");
}

3.Write a JAVA program to print the pattern as shown below.


Commented [1]: @[email protected] -
remove the space and include \t ,Also. Qn0 4 code to
be mentioned.
Regards,
Swathi
_Assigned to [email protected]_
Commented [2R1]: @swathi.ajjarapu@deensacademy.
com
Do we need to edit Part1 also?
_Reassigned to [email protected]_

Code: Commented [3R1]: Obviously !

public class pattern


{
public static void main(String[] args) {
System.out.println("*********");
System.out.println("*\t*");
System.out.println("*\t*");
System.out.println("*********");
System.out.println("*\t*");
System.out.println("*\t*");
System.out.println("*********");
}
}

4. Write a program to store name and age and display in the below format
Output:

Code:
public class program1
{
public static void main(String args[])
{
int age=15;
String name="Name";
char Section='A';
System.out.println("My Name is :"+name);
System.out.println("My age is :"+age);
}
}

II..List the errors in the given code


5..public class program10
public static void main (String args[])
{
int number1='4';
String 4='test';
}
Ans: int number1=4;
String ABS="test";
A digit cannot be a variable name
6.public class program11
{
public static void main (String args[])
{
int _number2=10;
}
}
Ans:No Error
7.public class program12
{
public static void main (String args[])
{
class String a="Name";
}
}
Ans:String a="Name";
8.public class program13
public static void main (String args[])
{
"Name" = x String;
}
Ans:String x="Name";
9.public class program14
public static void main (String args[])
{
int @number1=600;
}
Ans:int number1=600;
Variable name cannot start with@
10.public class program15 {
public static main(String[] args) {
System.out.println("Hello World Example);
}
}
Ans :System.out.println("Hello World Example”);

11.public class program16 {

public static void main (String args[])


{
String super="test";
}
Ans:String Super="test"; [super is a keyword]

III. Do the below programs have any errors?If yes,mention and write the output?

12. public class programa {

public static void main (String args[])


{
int _a = 10;
int $b = 20;
int C = 30;
int c = 40;
int result = _a + $b + C + c;
System.out.println("Result: " + result);

}
Ans:No errors,Result = 100
13. public class programb
{
public static void main(String[] args)
{
System.out.println("My name is:");System.out.println("Jane Doe");System.out.println("I am studying in Gr8"); }
}
Ans:My name is:
Jane Doe
I am studying in Gr8

14. public class programc


{
int x = 10;
public static void main(String[] args)
{
System.out.println("The number is" +x);
}
}
Ans:public class programc
public static void main(String[] args)
{
int x = 10;
System.out.println("The number is" +x);
}
}

*************************************************************************************************************

You might also like