Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Friday, February 7, 2014

Printing Text in Java - Code Example

This post contains a java code that prints a few sentences.








import java.awt.JobAttributes;
import javax.swing.JOptionPane;


public class Main {
 
 
 public static void main(String argS[]) {
  
  
  System.out.println("Hello World!");
  System.out.print("Welcome to Java Programming!");
  System.out.println(" This is a line following above line!.");
  
  
  JOptionPane.showMessageDialog(null, "Welcome to \n Java Programming!");
  
  System.exit(0);
   
 } 

}


Read More

Addition Example with Java

This post contains a java code that adds two input entered by the user and show the result.







import java.awt.JobAttributes;

import javax.swing.JOptionPane;

public class Addition {
 
 
 public static void main(String args[]) {
  
  String number1, number2; 
  Integer num1,num2,sum; 
  
  number1 = JOptionPane.showInputDialog("Enter first number:");
  number2 = JOptionPane.showInputDialog("Enter second number:");
  
  num1 = Integer.parseInt(number1);
  num2 = Integer.parseInt(number2);
  
  sum = num1 + num2; 
  
  
  JOptionPane.showMessageDialog(null, "The sum is "+sum,"Results",JOptionPane.INFORMATION_MESSAGE);
     
 }
}

Read More