0% found this document useful (0 votes)
19 views3 pages

Java Program Examples for Beginners

The document contains 4 Java code examples: 1) Declaring and assigning an integer variable. 2) A program that checks if a user-input number is positive or negative. 3) A program that checks if a user-input character is a vowel or consonant. 4) A simple "Hello World" program. For each example, the code and expected output is provided.
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)
19 views3 pages

Java Program Examples for Beginners

The document contains 4 Java code examples: 1) Declaring and assigning an integer variable. 2) A program that checks if a user-input number is positive or negative. 3) A program that checks if a user-input character is a vowel or consonant. 4) A simple "Hello World" program. For each example, the code and expected output is provided.
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

QUESTION NO 1

Write a program to declare a variable and assign a integer value in java ?

CODE

package assignment;

/**

* @author CH Tanzeel

*/

public class Assignment {

public static void main(String[] args) {

int x = 30; // declairde a variable & assignting value to it

[Link](x);

QUESTION NO 2:
Write a program to check number id positive or negative using java code?

Code:

package assignment;

import [Link];
public class Assignment {

public static void main(String[] args) {

[Link]("enter a number");

Scanner input =new Scanner([Link]);

int number = [Link]();

if(number<0){

[Link]("you input is in negative number");

else

[Link]("ypu input is in positive number");

Question number 3:
Write a program to check vowel and consonant in java ?

Code:

package assignment;

import [Link];

public class Assignment {


public static void main(String[] args) {

[Link]("enter a latter");

Scanner input =new Scanner([Link]);

char i=[Link](). charAt(0);

if(i=='a'|| i=='e'|| i=='i'||i=='o'||i=='u'){

[Link]("you enter a vovel letter");

else

[Link]("you enter a consonent ");

Question no 4:

Write a program to print hello world in java:

Code:

package assignment;

public class Assignment {

public static void main(String[] args) {

[Link]("helo world");

You might also like