Showing posts with label add two numbers in java. Show all posts
Showing posts with label add two numbers in java. Show all posts
Thursday, June 3, 2010
Array
Array is very important in programming to store data in array. i post the lesson next day.
Labels:
add two numbers in java,
array in java,
array-java
Thursday, April 22, 2010
Even or Odd program using java
This program will determine if the number inputted by the user is even or odd.
we use here a modulo operator to get the even or odd numbers.
Modulo - this operator use in programming to get the remainder.
sample program:
import java.util.Scanner;
public class EvenOdd
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num;
System.out.print("Enter a number:");
num=input.nextInt();
if(num%2==0)
{
System.out.print("Even number");
}
else if(num%2==1)
{
System.out.print("Odd Numbers");
}
}
}
we use here a modulo operator to get the even or odd numbers.
Modulo - this operator use in programming to get the remainder.
sample program:
import java.util.Scanner;
public class EvenOdd
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num;
System.out.print("Enter a number:");
num=input.nextInt();
if(num%2==0)
{
System.out.print("Even number");
}
else if(num%2==1)
{
System.out.print("Odd Numbers");
}
}
}
Labels:
add two numbers in java,
Even,
Modulo,
Odd
Sunday, April 18, 2010
Compute two numbers in java using user input
this program will ask the user to input two numbers and get the sum.
import java.io.*;
import java.util.Scanner;
public class getsum
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num1,num2;
int sum=0;
System.out.print("Enter First Number:");
num1=input.nextInt();
System.out.print("Enter Second Number:");
num2=input.nextInt();
sum=num1+num2;
System.out.print("The sum is:" + sum);
}
}
import java.io.*;
import java.util.Scanner;
public class getsum
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num1,num2;
int sum=0;
System.out.print("Enter First Number:");
num1=input.nextInt();
System.out.print("Enter Second Number:");
num2=input.nextInt();
sum=num1+num2;
System.out.print("The sum is:" + sum);
}
}
Subscribe to:
Posts (Atom)